#include <bits/stdc++.h>
using namespace std;
int q=0;
string dict = "0123456789";
string f(int n, int x)
{
string ans = "";
while (n != 0)
{
ans += dict[n % x];
n /= x;
}
string t = "";
for (int i = ans.length()-1; i >= 0; i--) t += ans[i];
return t;
}
void e(string s){
int d=s.size();
for(int i=0,j=d-1;i<d;i++,j--){
if(s[i]!=s[j]){
return;
}
}
q++;
}
int main()
{
int s,n,g=0;
cin>>n>>s;
while(g<n){
s++;
for(int j=2;j<10;j++){
e(f(s,j));
}
if(q>=2){
cout<<s<<endl;
q=0;
g++;
}
}
return 0;
}