#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }
inline long long tonum(string s) {long long v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string tostr(T x) {ostringstream sout;sout<<x;return sout.str();}



inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long mul(long long a, long long b, long long m) {
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}

long long pow(long long a, long long n, long long m) {
    if (n == 0) return 1 % m;
    long long t = pow(a, n/2, m);
    t = mul(t, t, m);
    if (n & 1) t = mul(t, a, m);
    return t;
}

bool is_prime(long long n) {
    if (n == 2) return true;
    if (!(n & 1) || n <= 1) return false;
    int a[] = {2, 3, 5, 7, 11, 13, 17, -1};
    long long s = 0, d = n-1;
    while (!(d & 1)) { ++s; d = d>>1; }
    for (int i = 0; a[i] != -1 && a[i] < n; ++i) {
        long long x = pow(a[i], d, n);
        int t;
        if (x != 1) {
            for (t = 0; t < s; ++t) {
                if (x == n-1) break;
                x = mul(x, x, n);
            }
            if (t == s) return false;
        }
    }
    return true;
}



int n, c;

long long conv(long long num) {
    string str = tostr(num);
    string str2 = str;
    reverse(ALL(str2));
    string res = str + tostr(c) + str2;
    
    return tonum(res);
}

int main() {
    while (cin >> n >> c) {
        if (c < 0) {
            if (n >= 2) { for (int i = 0; i < n*2; ++i) cout << 9; cout << endl; }
            else cout << 11 << endl;
        }
        else {
            long long num = 1;
            for (int i = 0; i < n; ++i) {
                num *= 10;
            }
            --num;

            for (long long i = num; i >= 0; --i) {
                long long j = conv(i);
                if (is_prime(j)) {
                    cout << j << endl;
                    break;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1236