#include<stdio.h>
#include<string.h>
#include<algorithm>
typedef long long ll;
using namespace std;
struct bign{
int d[1000];
int len;
bign(){
memset(d,0,sizeof(d));
len = 0;
}
};
bign change(char str[]){ //将整数转换为bign
bign a;
a.len = strlen(str);
for(int i=0;i<a.len;i++){
a.d[i] = str[a.len-1-i] - '0';
}
return a;
}
bool judge(bign a){ //判断是否是回文
for(int i=0; i <= a.len/2; i++){
if(a.d[i] != a.d[a.len-1-i]){
return false;
}
}
return true;
}
bign add(bign a,bign b){ //高精度a+b
bign c;
int carry = 0;
for(int i=0; i < a.len || i < b.len; i++){
int temp = a.d[i] + b.d[i] + carry;
c.d[c.len++] = temp % 10;
carry = temp / 10;
}
if(carry != 0){
c.d[c.len++] = carry;
}
return c;
}
void print(bign a){ //输出bign
for(int i = a.len-1; i >= 0; i--){
printf("%d",a.d[i]);
}
printf("\n");
}
int main(){
char str[1000];
int k,num=0;
while(scanf("%s %d",str,&k)!=EOF){
bign a = change(str);
while(num<k && judge(a)==false){
bign b = a;
reverse(b.d,b.d+b.len); //将字符串倒置
a = add(a,b);
num++;
}
print(a);
printf("%d\n",num);
}
return 0;
}