#include<stdio.h>
int count(int n);
int main()
{
int a[4],year,n,i,sum;
scanf("%d%d",&year,&n);
sum=year;
for(i=year;i<=9999;i++){
if(count(i)==n){
printf("%d %04d",sum-year,sum);
break;
}
sum++;
}
return 0;
}
int count(int n)
{
int num[10]={0},i,total=0;
char charc[4];
sprintf(charc,"%04d",n);//将数字转为字符串
for(i=0;i<4;i++)
num[charc[i]-'0']++;//只有四个数,用num的10个数去储存,数字字符-‘0’变为数字
for(i=0;i<10;i++)
if(num[i])
total++;//计数
return total;
}