#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int Jugement(int year,int num);
int main(){
int year,num,count=0;
scanf("%d %d",&year,&num);
while(Jugement(year,num)==0){
year++;
count++;
}
printf("%d %04d\n",count,year);
return 0;
}
int Jugement(int year,int num){
int set[10]={0}; //用一个set数组把出现过的数字赋值为1
int size = 0;
if(year<1000){
set[0] = 1;
size++;
}
while(year){
int y = year%10;
if(set[y]==0){
set[y] = 1;
size++;
}
year = year/10;
}
if(size==num){
return 1;
}else{
return 0;
}
}