using namespace std;
const int maxn = 1e6+9;
string change(int n,int s)
{
if (s == 10)
{
queue<int>st;
while (n)
{
st.push(n % s);
n /= s;
}
string str = "";
while (!st.empty())
{
str += st.front();
st.pop();
}
return str;
}
stack<int>st;
while (n)
{
st.push(n % s);
n /= s;
}
string str = "";
while (!st.empty())
{
str += st.top();
st.pop();
}
return str;
}
int stoi(string s)
{
int plus = 1,sum = 0;
for (int i = 0; i < s.length(); i++)
{
sum += plus * (s[i] + '0');
plus *= 10;
}
return sum;
}
string to_string(int s)
{
string str = "";
while (s)
{
str += (s % 10 + '0');
s /= 10;
}
return str;
}
bool isP(string n,int s)
{
n = change(stoi(n),s);
int left = 0,right = n.length() - 1;
while (left <= right)
{
if (n[left] != n[right])
return 0;
}
return 1;
}
int main()
{
int n,s;
cin >> n >> s;
while (n)
{
int cnt = 0;
bool flag = 0;
for (int i = 2; i <= 10; i++)
{
if (isP(to_string(s),i)) cnt++;
if (cnt == 2)
{
flag = 1;
break;
}
}
if (flag)
{
cout << s << '\n';
n--;
}
s++;
}
return 0;
}