#include<cstdio>
using namespace std;
struct Node{
int last;
int yu;
int val;
}node[100000];
int n,m,len=0;
bool used[1001];
int res[6000];
void out(int tail)
{
res[++len]=node[tail].val;
if(node[tail].last==0){
for(int i=len;i>=1;i--)
printf("%d",res[i]);
return;
}
out(node[tail].last);
}
void bfs()
{ int head=-1,tail=1;
node[0].yu=0;
node[0].val=0;
node[0].last=0;
do{
head++;
if(used[node[head].yu]==1) continue;
for(int i=0;i<n;i++){
if(head==0&&i==0)continue;
node[tail].val=i;
node[tail].last=head;
node[tail].yu=((node[head].yu*10)%m+i)%m;
if(node[tail].yu==0){out(tail);return;}
tail++;
}
used[node[head].yu]=1;
}while(head<tail);
return ;
}
int main()
{
scanf("%d%d",&n,&m);
bfs();
return 0;
}