#include <bits/stdc++.h>

using namespace std;

#ifdef ONLINE_JUDGE
#define OJ 1
#else
#define OJ 0
#endif

#define dd				double
#define ll 				long long
#define pb 				push_back
#define mp 				make_pair
#define X				first
#define Y				second
#define forn( i, n ) 	for( ll i = 0; i < (ll) (n); i ++ )
#define endl 			'\n'

#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

struct __s { __s() {
		//srand( time( NULL ) );
		//freopen( "input.txt", "r", stdin ); //freopen( "output.txt", "w", stdout );
		if( OJ ) { ios_base::Init i; cin.sync_with_stdio( 0 ); cin.tie( 0 ); }
	} ~__s() {
		if( !OJ ) TIMESTAMP;
		ll n; cin >> n;
	}
} __S;

ll a, b;
ll p[31111111];
vector< ll > pr;
ll c[18];

ll pal( ll x ) {
    ll i = 1;
    ll res = 0;
    while( x >= c[i] ) {
        res += 9 * c[( i - 1 ) / 2];
        i ++;
    }
    for( ll i1 = 1; i1 <= 9; i1 ++ ) {
        ll y;
        if( i <= 2 ) {
            if( i == 1 )
                y = i1;
            else
                y = i1 * 10 + i1;
            if( y <= x )
                res ++;
        }
        else
        for( ll i2 = 0; i2 <= 9; i2 ++ ) {
            if( i <= 4 ) {
                if( i == 3 )
                    y = i1 * 100 + i2 * 10 + i1;
                else
                    y = i1 * 1000 + i2 * 100 + i2 * 10 + i1;
                if( y <= x )
                    res ++;
            }
            else
            for( ll i3 = 0; i3 <= 9; i3 ++ ) {
                if( i <= 6 ) {
                    if( i == 5 )
                        y = i1 * 10000 + i2 * 1000 + i3 * 100 + i2 * 10 + i1;
                    else
                        y = i1 * 100000 + i2 * 10000 + i3 * 1000 + i3 * 100 + i2 * 10 + i1;
                    if( y <= x )
                        res ++;
                }
                else
                for( ll i4 = 0; i4 <= 9; i4 ++ ) {
                    if( i <= 8 ) {
                        if( i == 7 )
                            y = i1 * 1000000 + i2 * 100000 + i3 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
                        else
                            y = i1 * 10000000 + i2 * 1000000 + i3 * 100000 + i4 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
                        if( y <= x )
                            res ++;
                    }
                }
            }
        }
    }
    return res;
}

bool check( ll x ) {
    return p[x] * b <= a * pal( x );
}

int main( void ) {
    ll m = 1200000;
    c[0] = 1;
    forn( i, 17 ) {
        c[i + 1] = c[i] * 10;
    }
    for( ll i = 2; i <= m; i ++ ) {
        if( p[i] ) {
            p[i] = p[i - 1];
            continue;
        }
        for( ll j = i * i; j <= m; j += i )
            p[j] = 1;
        p[i] = p[i - 1] + 1;
        pr.pb( i );
    }
    cin >> a >> b;
    /*ll l = 0;
    ll r = m;
    while( r - l > 1 ) {
        ll s = ( r + l ) / 2;
        if( check( s ) ) {
            l = s;
        } else {
            r = s;
        }
    }
    cout << ( check( r ) ? r : l ) << endl;*/
    ll ans = 0;
    forn( i, pr.size() ) {
        ll x = pr[i] - 1;
        if( check( x ) ) {
            ans = max( ans, x );
        }
    }
    cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef ONLINE_JUDGE
#define OJ 1
#else
#define OJ 0
#endif

#define dd				double
#define ll 				long long
#define pb 				push_back
#define mp 				make_pair
#define X				first
#define Y				second
#define forn( i, n ) 	for( ll i = 0; i < (ll) (n); i ++ )
#define endl 			'\n'

#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

struct __s { __s() {
		//srand( time( NULL ) );
		//freopen( "input.txt", "r", stdin ); //freopen( "output.txt", "w", stdout );
		if( OJ ) { ios_base::Init i; cin.sync_with_stdio( 0 ); cin.tie( 0 ); }
	} ~__s() {
		if( !OJ ) TIMESTAMP;
		ll n; cin >> n;
	}
} __S;

ll a, b;
ll p[11111111];
vector< ll > pr;
ll q[11111111];
ll c[18];

ll pal( ll x ) {
    ll i = 1;
    ll res = 0;
    while( x >= c[i] ) {
        res += 9 * c[( i - 1 ) / 2];
        i ++;
    }
    for( ll i1 = 1; i1 <= 9; i1 ++ ) {
        ll y;
        if( i <= 2 ) {
            if( i == 1 )
                y = i1;
            else
                y = i1 * 10 + i1;
            if( y <= x )
                res ++;
        }
        else
        for( ll i2 = 0; i2 <= 9; i2 ++ ) {
            if( i <= 4 ) {
                if( i == 3 )
                    y = i1 * 100 + i2 * 10 + i1;
                else
                    y = i1 * 1000 + i2 * 100 + i2 * 10 + i1;
                if( y <= x )
                    res ++;
            }
            else
            for( ll i3 = 0; i3 <= 9; i3 ++ ) {
                if( i <= 6 ) {
                    if( i == 5 )
                        y = i1 * 10000 + i2 * 1000 + i3 * 100 + i2 * 10 + i1;
                    else
                        y = i1 * 100000 + i2 * 10000 + i3 * 1000 + i3 * 100 + i2 * 10 + i1;
                    if( y <= x )
                        res ++;
                }
                else
                for( ll i4 = 0; i4 <= 9; i4 ++ ) {
                    if( i <= 8 ) {
                        if( i == 7 )
                            y = i1 * 1000000 + i2 * 100000 + i3 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
                        else
                            y = i1 * 10000000 + i2 * 1000000 + i3 * 100000 + i4 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
                        if( y <= x )
                            res ++;
                    }
                }
            }
        }
    }
    return res;
}

bool check( ll x ) {
    return p[x] * b <= a * pal( x );
}

int main( void ) {
    c[0] = 1;
    forn( i, 17 ) {
        c[i + 1] = c[i] * 10;
    }
    for( ll i = 2; i <= 1000000; i ++ ) {
        if( p[i] ) {
            p[i] = p[i - 1];
            continue;
        }
        for( ll j = i * i; j <= 1000000; j += i )
            p[j] = 1;
        p[i] = p[i - 1] + 1;
        pr.pb( i );
    }
    cin >> a >> b;
    ll ans = 1;
    forn( i, pr.size() ) {
        if( b * p[pr[i] - 1] <= a * pal( pr[i] - 1 ) ) {
            ans = max( ans, pr[i] - 1 );
            //cout << pr[i] - 1 << " " <<p[pr[i] - 1] << " " << pal( pr[i] - 1 ) << endl;
        }
    }
    cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef ONLINE_JUDGE
#define OJ 1
#else
#define OJ 0
#endif

#define dd				double
#define ll 				long long
#define pb 				push_back
#define mp 				make_pair
#define X				first
#define Y				second
#define forn( i, n ) 	for( ll i = 0; i < (ll) (n); i ++ )
#define endl 			'\n'

#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

struct __s { __s() {
		//srand( time( NULL ) );
		//freopen( "input.txt", "r", stdin ); //freopen( "output.txt", "w", stdout );
		if( OJ ) { ios_base::Init i; cin.sync_with_stdio( 0 ); cin.tie( 0 ); }
	} ~__s() {
		if( !OJ ) TIMESTAMP;
		ll n; cin >> n;
	}
} __S;

ll a, b;
ll p[31111111];
vector< ll > pr;
ll c[18];

ll pal( ll x ) {
    ll i = 1;
    ll res = 0;
    while( x >= c[i] ) {
        res += 9 * c[( i - 1 ) / 2];
        i ++;
    }
    for( ll i1 = 1; i1 <= 9; i1 ++ ) {
        ll y;
        if( i <= 2 ) {
            if( i == 1 )
                y = i1;
            else
                y = i1 * 10 + i1;
            if( y <= x )
                res ++;
        }
        else
        for( ll i2 = 0; i2 <= 9; i2 ++ ) {
            if( i <= 4 ) {
                if( i == 3 )
                    y = i1 * 100 + i2 * 10 + i1;
                else
                    y = i1 * 1000 + i2 * 100 + i2 * 10 + i1;
                if( y <= x )
                    res ++;
            }
            else
            for( ll i3 = 0; i3 <= 9; i3 ++ ) {
                if( i <= 6 ) {
                    if( i == 5 )
                        y = i1 * 10000 + i2 * 1000 + i3 * 100 + i2 * 10 + i1;
                    else
                        y = i1 * 100000 + i2 * 10000 + i3 * 1000 + i3 * 100 + i2 * 10 + i1;
                    if( y <= x )
                        res ++;
                }
                else
                for( ll i4 = 0; i4 <= 9; i4 ++ ) {
                    if( i <= 8 ) {
                        if( i == 7 )
                            y = i1 * 1000000 + i2 * 100000 + i3 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
                        else
                            y = i1 * 10000000 + i2 * 1000000 + i3 * 100000 + i4 * 10000 + i4 * 1000 + i3 * 100 + i2 * 10 + i1;
                        if( y <= x )
                            res ++;
                    }
                }
            }
        }
    }
    return res;
}

bool check( ll x ) {
    x = pr[x] - 1;
    return p[x] * b <= a * pal( x );
}

int main( void ) {
    ll m = 2000000;
    c[0] = 1;
    forn( i, 17 ) {
        c[i + 1] = c[i] * 10;
    }
    for( ll i = 2; i <= m; i ++ ) {
        if( p[i] ) {
            p[i] = p[i - 1];
            continue;
        }
        for( ll j = i * i; j <= m; j += i )
            p[j] = 1;
        p[i] = p[i - 1] + 1;
        pr.pb( i );
    }
    cin >> a >> b;
    ll l = 0;
    ll r = pr.size() - 1;
    while( r - l > 1 ) {
        ll s = ( r + l ) / 2;
        if( check( s ) ) {
            l = s;
        } else {
            r = s;
        }
    }
    cout << ( check( r ) ? pr[r] : pr[l] ) - 1 << endl;
	return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 1000000000
#define VISITED true
#define UNVISITED false
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define All(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)
#define odd(n) (n & 1)
#define even(n) !odd(n)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <int, int> ii;
typedef vector <int> vi;
const int OO = (int)1e9;
int counter[10000005] = {0};
bitset<10000001> bs;
void sieve(ll n)
{
    ll sieve_size = n+1;
    bs.set();
    int c = 0;
    bs[0] = bs[1] = 0;
    c++;
    counter[0] = counter[1] = 0;
    counter[2] = c;
    for (register ll i=3; i*i<=sieve_size; i+=2)
    {
        if (bs[i])
        {
            for (register ll j=i*i; j<=sieve_size; j+=i) bs[j]=0;
            c++;
        }
        counter[i] = counter[i+1] = c;
    }
    ll sq = (ll) sqrt(n+1);
    if (even(sq)) sq++;
    for (ll i=sq; i<n+1; i+=2)
    {
        if (bs[i])
            c++;
        counter[i] = counter[i+1] = c;
    }
}
bool Ispalindrome(int n)
{
    int a[7];
    int c = 0;
    while (n)
    {
        a[c++] = n % 10;
        n /= 10;
    }
    for (int i=0; i<c; ++i)
        if (a[i] != a[c-i-1])
            return false;
    return true;
}
int main()
{
    ll p, q;
    cin>>p>>q;
    sieve(10000000);
    int k = 10998;
    int i;
    bool yes = false;
    int d = 0;
    for (i=10000000; i>=1; i--)
    {
        if ((q * counter[i]) <= (k * p))
        {
            yes = true;
            break;
        }
        if (Ispalindrome(i))
        {
//                d++;
            k--;
        }
    }
//    cout<<endl<<d<<endl;
    cout<<i<<endl;
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 1000000000
#define VISITED true
#define UNVISITED false
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define All(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)
#define odd(n) (n & 1)
#define even(n) !odd(n)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <int, int> ii;
typedef vector <int> vi;
const int OO = (int)1e9;
ll counter[10000005] = {0};
bitset<10000005> bs;
void sieve(ll n)
{
    ll sieve_size = n+1;
    bs.set();
    ll c = 0;
    bs[0] = bs[1] = 0;
    c++;
    counter[0] = counter[1] = 0;
    counter[2] = c;
    for ( ll i=3; i*i<=sieve_size; i+=2)
    {
        if (bs[i])
        {
            for (ll j=i*i; j<=sieve_size; j+=i) bs[j]=0;
            c++;
        }
        counter[i] = counter[i+1] = c;
    }
    ll sq = (ll) sqrt(n+1);
    if (even(sq)) sq++;
    for (ll i=sq; i<n+1; i+=2)
    {
        if (bs[i])
            c++;
        counter[i] = counter[i+1] = c;
    }
}
bool Ispalindrome(ll n)
{
    ll a[7];
    ll c = 0;
    while (n)
    {
        a[c++] = n % 10;
        n /= 10;
    }
    for (int i=0; i<c; ++i)
        if (a[i] != a[c-i-1])
            return false;
    return true;
}
int main()
{
    ll p, q;
    cin>>p>>q;
    sieve(10000000);
    ll k = 10998;
    ll i;
    bool yes = false;
    int d = 0;
    for (i=10000000; i>=1; i--)
    {
        if ((q * counter[i]) <= (k * p))
        {
            yes = true;
            break;
        }
        if (Ispalindrome(i))
        {
//                d++;
            k--;
        }
    }
//    cout<<endl<<d<<endl;
    cout<<i<<endl;
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 1000000000
#define VISITED true
#define UNVISITED false
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define All(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)
#define odd(n) (n & 1)
#define even(n) !odd(n)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <int, int> ii;
typedef vector <int> vi;
const int OO = (int)1e9;
int counter[10000005] = {0};
bitset<10000005> bs;
void sieve(ll n)
{
    ll sieve_size = n+1;
    bs.set();
    int c = 0;
    bs[0] = bs[1] = 0;
    c++;
    counter[0] = counter[1] = 0;
    counter[2] = c;
    for (register ll i=3; i*i<=sieve_size; i+=2)
    {
        if (bs[i])
        {
            for (register ll j=i*i; j<=sieve_size; j+=i) bs[j]=0;
            c++;
        }
        counter[i] = counter[i+1] = c;
    }
    ll sq = (ll) sqrt(n+1);
    if (even(sq)) sq++;
    for (ll i=sq; i<n+1; i+=2)
    {
        if (bs[i])
            c++;
        counter[i] = counter[i+1] = c;
    }
}
bool Ispalindrome(int n)
{
    int a[7];
    int c = 0;
    while (n)
    {
        a[c++] = n % 10;
        n /= 10;
    }
    for (int i=0; i<c; ++i)
        if (a[i] != a[c-i-1])
            return false;
    return true;
}
int main()
{
    ll p, q;
    cin>>p>>q;
    sieve(10000000);
    int k = 10998;
    int i;
    bool yes = false;
    int d = 0;
    for (i=10000000; i>=1; i--)
    {
        if ((q * counter[i]) <= (k * p))
        {
            yes = true;
            break;
        }
        if (Ispalindrome(i))
        {
//                d++;
            k--;
        }
    }
//    cout<<endl<<d<<endl;
    cout<<i<<endl;
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 1000000000
#define VISITED true
#define UNVISITED false
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define All(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)
#define odd(n) (n & 1)
#define even(n) !odd(n)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <int, int> ii;
typedef vector <int> vi;
const int OO = (int)1e9;
int counter[10000005] = {0};
bitset<10000001> bs;
void sieve(ll n)
{
    ll sieve_size = n+1;
    bs.set();
    int c = 0;
    bs[0] = bs[1] = 0;
    c++;
    counter[0] = counter[1] = 0;
    counter[2] = c;
    for (register ll i=3; i*i<=sieve_size; i+=2)
    {
        if (bs[i])
        {
            for (register ll j=i*i; j<=sieve_size; j+=i) bs[j]=0;
            c++;
        }
        counter[i] = counter[i+1] = c;
    }
    ll sq = (ll) sqrt(n+1);
    if (even(sq)) sq++;
    for (ll i=sq; i<n+1; i+=2)
    {
        if (bs[i])
            c++;
        counter[i] = counter[i+1] = c;
    }
}
bool Ispalindrome(int n)
{
    int a[7];
    int c = 0;
    while (n)
    {
        a[c++] = n % 10;
        n /= 10;
    }
    for (int i=0; i<c; ++i)
        if (a[i] != a[c-i-1])
            return false;
    return true;
}
int main()
{
    iOS;
    ll p, q;
    cin>>p>>q;
    sieve(10000000);
    int k = 10998;
    int i;
    bool yes = false;
    int d = 0;
    for (i=10000000; i>=1; i--)
    {
        if ((q * counter[i]) <= (k * p))
        {
            yes = true;
            break;
        }
        if (Ispalindrome(i))
        {
//                d++;
            k--;
        }
    }
//    cout<<endl<<d<<endl;
    yes ? cout<<i<<endl : cout<<"Palindromic tree is better than splay tree"<<endl;
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <string.h>
#include <ctype.h>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <time.h>
#include <bitset>
#include <sstream>
#define Set(name,value) memset(name,value,sizeof(name))
#define INF 1000000000
#define VISITED true
#define UNVISITED false
#define intr int register
#define rep(i,n) for (intr i=0;i<n;i++)
#define All(a) a.begin(), a.end()
#define iOS ios_base::sync_with_stdio(false)
#define odd(n) (n & 1)
#define even(n) !odd(n)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <int, int> ii;
typedef vector <int> vi;
const int OO = (int)1e9;
int counter[10000005] = {0};
bitset<10000001> bs;
void sieve(ll n)
{
    ll sieve_size = n+1;
    bs.set();
    int c = 0;
    bs[0] = bs[1] = 0;
    c++;
    counter[0] = counter[1] = 0;
    counter[2] = c;
    for (register ll i=3; i*i<=sieve_size; i+=2)
    {
        if (bs[i])
        {
            for (register ll j=i*i; j<=sieve_size; j+=i) bs[j]=0;
            c++;
        }
        counter[i] = counter[i+1] = c;
    }
    ll sq = (ll) sqrt(n+1);
    if (even(sq)) sq++;
    for (ll i=sq; i<n+1; i+=2)
    {
        if (bs[i])
            c++;
        counter[i] = counter[i+1] = c;
    }
}
bool Ispalindrome(int n)
{
    int a[7];
    int c = 0;
    while (n)
    {
        a[c++] = n % 10;
        n /= 10;
    }
    for (int i=0; i<c; ++i)
        if (a[i] != a[c-i-1])
            return false;
    return true;
}
int main()
{
    iOS;
    ll p, q;
    cin>>p>>q;
    sieve(10000000);
    int k = 10998;
    int i;
    bool yes = false;
    int d = 0;
    for (i=10000000; i>=1; i--)
    {
        if ((q * counter[i]) <= (k * p))
        {
            yes = true;
            break;
        }
        if (Ispalindrome(i))
        {
//                d++;
            k--;
        }
    }
//    cout<<endl<<d<<endl;
    cout<<i<<endl;
    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int p,q,sum1,sum2,ma;
bool pal(int x)
{
	int t=x,w=0;
	int a[20];
	while (t>0){
		a[w]=t%10;
		t=t/10;
		w++;
	}
	bool f=true;
	for (int i=0;i<w/2;i++)
	{
		if (a[i]!=a[w-i-1]) f=false;
	}
	return f;
}
int main()
{
	cin>>p>>q;
	int k;
	for (k=1;k<=1000;k++){
		sum1=0,sum2=0;
		for (int i=2;i<=k;i++)
		{
			bool f=1;
			for (int j=2;j*j<=i;j++)
			{
				if (i%j==0) f=0;
			}
			if (f) sum1++;
		}
		for (int  i=1;i<=k;i++)
		{
			sum2+=pal(i);
		}
		if (q*sum1<=p*sum2) ma=k;
	}
	cout<<ma;
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int p,q,sum1,sum2,ma;
bool pal(int x)
{
	int t=x,w=0;
	int a[20];
	while (t>0){
		a[w]=t%10;
		t=t/10;
		w++;
	}
	bool f=true;
	for (int i=0;i<w/2;i++)
	{
		if (a[i]!=a[w-i-1]) f=false;
	}
	return f;
}
int main()
{
	cin>>p>>q;
	int k;
	for (k=1;k<=100000;k++){
		bool f=1;
		for (int i=2;i*i<=k;i++)
		{
			if (k%i==0) f=0;
		}
		if (k<2) f=false;
		if (f) sum1++;
		sum2+=pal(k);
		if (q*sum1<=p*sum2) ma=k;
	}
	cout<<ma;
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int p,q,sum1,sum2,ma;
bool pal(int x)
{
	int t=x,w=0;
	int a[20];
	while (t>0){
		a[w]=t%10;
		t=t/10;
		w++;
	}
	bool f=true;
	for (int i=0;i<w/2;i++)
	{
		if (a[i]!=a[w-i-1]) f=false;
	}
	return f;
}
int main()
{
	cin>>p>>q;
	int k;
	for (k=1;k<=430000;k++){
		bool f=1;
		for (int i=2;i*i<=k;i++)
		{
			if (k%i==0) f=0;
		}
		if (k<2) f=false;
		if (f) sum1++;
		sum2+=pal(k);
		if (q*sum1<=p*sum2) ma=k;
	}
	cout<<ma;
	return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
using namespace std;
int p,q,sum1,sum2,ma;
bool f[2000005];
void prime()
{
	f[1]=1;
	for (int i=2;i*i<2000005;i++)
	{
		if (!f[i]){
			for (int j=2;i*j<=2000005;j++) f[i*j]=1;
		}
	}
}
bool pal(int x)
{
	int t=x,w=0;
	int a[20];
	while (t>0){
		a[w]=t%10;
		t=t/10;
		w++;
	}
	bool f=true;
	for (int i=0;i<w/2;i++)
	{
		if (a[i]!=a[w-i-1]) f=false;
	}
	return f;
}
int main()
{
	prime();
	cin>>p>>q;
	int k;
	for (k=1;k<=2000000;k++){

		if (!f[k]) sum1++;
		sum2+=pal(k);
		if (q*sum1<=p*sum2) ma=k;
	}
	cout<<ma;
	return 0;
}


#include <iostream>

using namespace std;

const int MAXN = 1e7;
bool np[MAXN], pal[MAXN];

int main() {
    np[1] = 1;
    for(int p = 2; p < MAXN; p++) {
        if(!np[p]) {
            for(int q = 2*p; q < MAXN; q += p) {
                np[q] = 1;
            }
        }
    }
    for(int n = 1; n < MAXN; n++) {
        int _n = n;
        int m = 0;
        while(_n) {
            m = m*10 + (_n) % 10;
            _n /= 10;
        }
        if(n == m)
            pal[n] = 1;
    }
    long long pi = 0;
    long long rub = 0;
    int p, q;
    cin >> p >> q;
    int ans;
    for(int n = 1; n < MAXN; n++) {
        rub += pal[n];
        pi += !np[n];
        if(q*pi <= p*rub) {
            ans = n;
        }
    }
    cout << ans << '\n';
}


#include <iostream>

using namespace std;

const int MAXN = 1e8;
bool np[MAXN], pal[MAXN];

int main() {
    np[1] = 1;
    for(int p = 2; p < MAXN; p++) {
        if(!np[p]) {
            for(int q = 2*p; q < MAXN; q += p) {
                np[q] = 1;
            }
        }
    }
    for(int n = 1; n < MAXN; n++) {
        int _n = n;
        int m = 0;
        while(_n) {
            m = m*10 + (_n) % 10;
            _n /= 10;
        }
        if(n == m)
            pal[n] = 1;
    }
    int pi = 0;
    int rub = 0;
    int p, q;
    cin >> p >> q;
    int ans;
    for(int n = 1; n < MAXN; n++) {
        rub += pal[n];
        pi += !np[n];
        if(q*pi <= p*rub) {
            ans = n;
        }
    }
    cout << ans << '\n';
}


#include <iostream>

using namespace std;

const int MAXN = 1e6;
bool np[MAXN], pal[MAXN];

int main() {
    np[1] = 1;
    for(int p = 2; p < MAXN; p++) {
        if(!np[p]) {
            for(int q = 2*p; q < MAXN; q += p) {
                np[q] = 1;
            }
        }
    }
    for(int n = 1; n < MAXN; n++) {
        int _n = n;
        int m = 0;
        while(_n) {
            m = m*10 + (_n) % 10;
            _n /= 10;
        }
        if(n == m) pal[n] = 1;
    }
    int pi = 0;
    int rub = 0;
    int p, q;
    cin >> p >> q;
    for(int n = 1;; n++) {
        rub += pal[n];
        pi += !np[n];
        if(q*pi > p*rub) {
            cout << n-1;
            return 0;
        }
    }
}


#include <iostream>

using namespace std;

const int MAXN = 1e7;
bool np[MAXN], pal[MAXN];

int main() {
    np[1] = 1;
    for(int p = 2; p < MAXN; p++) {
        if(!np[p]) {
            for(int q = 2*p; q < MAXN; q += p) {
                np[q] = 1;
            }
        }
    }
    for(int n = 1; n < MAXN; n++) {
        int _n = n;
        int m = 0;
        while(_n) {
            m = m*10 + (_n) % 10;
            _n /= 10;
        }
        if(n == m)
            pal[n] = 1;
    }
    int pi = 0;
    int rub = 0;
    int p, q;
    cin >> p >> q;
    int ans;
    for(int n = 1; n < MAXN; n++) {
        rub += pal[n];
        pi += !np[n];
        if(q*pi <= p*rub) {
            ans = n;
        }
    }
    cout << ans << '\n';
}


#include <iostream>

using namespace std;

const int MAXN = 1e6;
bool np[MAXN], pal[MAXN];

int main() {
    np[1] = 1;
    for(int p = 2; p < MAXN; p++) {
        if(!np[p]) {
            for(int q = 2*p; q < MAXN; q += p) {
                np[q] = 1;
            }
        }
    }
    for(int n = 1; n < MAXN; n++) {
        int _n = n;
        int m = 0;
        while(_n) {
            m = m*10 + (_n) % 10;
            _n /= 10;
        }
        if(n == m)
            pal[n] = 1;
    }
    int pi = 0;
    int rub = 0;
    int p, q;
    cin >> p >> q;
    int ans;
    for(int n = 1; n < MAXN; n++) {
        rub += pal[n];
        pi += !np[n];
        if(q*pi <= p*rub) {
            ans = n;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=1e6+7;

int a[maxn],b[maxn],nt[maxn],pl[maxn],res,p,q,s[maxn],top;

void NT()
{
    a[1]=1;
    for (int i=2; i<=1000; ++i)
        if (a[i]==0)
        {
            for (int j=2; j<=1000000/i; ++j)
                a[i*j]=1;
        }
}

bool check(int k)
{
    top=0;
    while (k!=0)
    {
        int tmp=k%10;
        s[++top]=tmp;
        k=k/10;
    }
    for (int z=1; z<=top; ++z)
        if (s[z]!=s[top-z+1]) return true;
    return false;
}

void Palin()
{
    for (int i=1; i<=1000000; ++i)
        if (check(i)) b[i]=1;
}

void Init()
{
    for (int i=1; i<=1000000; ++i)
    {
        if (a[i]==0) nt[i]=nt[i-1]+1;
        else nt[i]=nt[i-1];
        if (b[i]==0) pl[i]=pl[i-1]+1;
        else pl[i]=pl[i-1];
    }
}

int main()
{
    cin >> p >> q;
    NT();
    Palin();
    Init();

    for (int i=1; i<=1000000; ++i)
        if (nt[i]*q<=pl[i]*p) res=i;
        else break;
    cout << res;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=1e7+7;

long long a[maxn],b[maxn],nt[maxn],pl[maxn],res,p,q,s[maxn],top;

void NT()
{
    a[1]=1;
    for (int i=2; i<=5000; ++i)
        if (a[i]==0)
        {
            for (int j=i; j<=5000000/i; ++j)
                a[i*j]=1;
        }
}

bool check(int k)
{
    top=0;
    while (k!=0)
    {
        int tmp=k%10;
        s[++top]=tmp;
        k=k/10;
    }
    for (int z=1; z<=top; ++z)
        if (s[z]!=s[top-z+1]) return true;
    return false;
}

void Palin()
{
    for (int i=1; i<=5000000; ++i)
        if (check(i)) b[i]=1;
}

void Init()
{
    for (int i=1; i<=5000000; ++i)
    {
        if (a[i]==0) nt[i]=nt[i-1]+1;
        else nt[i]=nt[i-1];
        if (b[i]==0) pl[i]=pl[i-1]+1;
        else pl[i]=pl[i-1];
    }
}

int main()
{
    cin >> p >> q;
    NT();
    Palin();
    Init();
    for (int i=1; i<=5000000; ++i)
        if (1ll*nt[i]*q<=1ll*pl[i]*p) res=i;
    cout << res;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=5e6+7;

long long a[maxn],b[maxn],nt[maxn],pl[maxn],res,p,q,s[maxn],top;

void NT()
{
    a[1]=1;
    for (int i=2; i<=5000; ++i)
        if (a[i]==0)
        {
            for (int j=i; j<=5000000/i; ++j)
                a[i*j]=1;
        }
}

bool check(int k)
{
    top=0;
    while (k!=0)
    {
        int tmp=k%10;
        s[++top]=tmp;
        k=k/10;
    }
    for (int z=1; z<=top; ++z)
        if (s[z]!=s[top-z+1]) return true;
    return false;
}

void Palin()
{
    for (int i=1; i<=5000000; ++i)
        if (check(i)) b[i]=1;
}

void Init()
{
    for (int i=1; i<=5000000; ++i)
    {
        if (a[i]==0) nt[i]=nt[i-1]+1;
        else nt[i]=nt[i-1];
        if (b[i]==0) pl[i]=pl[i-1]+1;
        else pl[i]=pl[i-1];
    }
}

int main()
{
    cin >> p >> q;
    NT();
    Palin();
    Init();
    for (int i=1; i<=5000000; ++i)
        if (1ll*nt[i]*q<=1ll*pl[i]*p) res=i;
    cout << res;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=1e6+7;

int a[maxn],b[maxn],nt[maxn],pl[maxn],res,p,q,s[maxn],top;

void NT()
{
    a[1]=1;
    for (int i=2; i<=1000; ++i)
        if (a[i]==0)
        {
            for (int j=2; j<=1000000/i; ++j)
                a[i*j]=1;
        }
}

bool check(int k)
{
    top=0;
    while (k!=0)
    {
        int tmp=k%10;
        s[++top]=tmp;
        k=k/10;
    }
    for (int z=1; z<=top; ++z)
        if (s[z]!=s[top-z+1]) return true;
    return false;
}

void Palin()
{
    for (int i=1; i<=1000000; ++i)
        if (check(i)) b[i]=1;
}

void Init()
{
    for (int i=1; i<=1000000; ++i)
    {
        if (a[i]==0) nt[i]=nt[i-1]+1;
        else nt[i]=nt[i-1];
        if (b[i]==0) pl[i]=pl[i-1]+1;
        else pl[i]=pl[i-1];
    }
}

int main()
{
    cin >> p >> q;
    NT();
    Palin();
    Init();

    for (int i=1; i<=1000000; ++i)
        if (nt[i]*q<=pl[i]*p) res=i;
    cout << res;
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=1e6+7;

int a[maxn],b[maxn],nt[maxn],pl[maxn],res,p,q,s[maxn],top;

void NT()
{
    a[1]=1;
    for (int i=2; i<=1000; ++i)
        if (a[i]==0)
        {
            for (int j=2; j<=1000000/i; ++j)
                a[i*j]=1;
        }
}

bool check(int k)
{
    top=0;
    while (k!=0)
    {
        int tmp=k%10;
        s[++top]=tmp;
        k=k/10;
    }
    for (int z=1; z<=top; ++z)
        if (s[z]!=s[top-z+1]) return true;
    return false;
}

void Palin()
{
    for (int i=1; i<=1000000; ++i)
        if (check(i)) b[i]=1;
}

void Init()
{
    for (int i=1; i<=1000000; ++i)
    {
        if (a[i]==0) nt[i]=nt[i-1]+1;
        else nt[i]=nt[i-1];
        if (b[i]==0) pl[i]=pl[i-1]+1;
        else pl[i]=pl[i-1];
    }
}

int main()
{
    cin >> p >> q;
    NT();
    Palin();
    Init();
    for (int i=1; i<=1000000; ++i)
        if (1ll*nt[i]*q<=1ll*pl[i]*p) res=i;
    cout << res;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int i,m,p,q,t1,t2;

inline bool check1(int x)
{
	if (x==1)
		return false;
	for (int i=2;i*i<=x;i++)
		if (! (x%i))
			return false;
	return true;
}

inline bool check2(int x)
{
	char c[10];
	c[0]=0;
	for (;x;x=x/10)
		c[0]++,c[c[0]]=x%10;
	for (int i=1;i<=c[0];i++)
		if (c[i]!=c[c[0]+1-i])
			return false;
	return true;
}

int main()
{
	scanf("%d%d",&p,&q);
	for (i=1;i<=1000000;i++)
	{
		if (check1(i))
			t1++;
		if (check2(i))
			t2++;
		if (q*t1<=p*t2)
			m=max(m,i);
	}
	if (m)
		printf("%d\n",m);
	else
		printf("Palindromic tree is better than splay tree\n");
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int i,m,p,q,t1,t2;

inline bool check1(int x)
{
	if (x==1)
		return false;
	for (int i=2;i*i<=x;i++)
		if (! (x%i))
			return false;
	return true;
}

inline bool check2(int x)
{
	char c[10];
	c[0]=0;
	for (;x;x=x/10)
		c[0]++,c[c[0]]=x%10;
	for (int i=1;i<=c[0];i++)
		if (c[i]!=c[c[0]+1-i])
			return false;
	return true;
}

int main()
{
	scanf("%d%d",&p,&q);
	for (i=1;i<=1200000;i++)
	{
		if (check1(i))
			t1++;
		if (check2(i))
			t2++;
		if (1LL*q*t1<=1LL*p*t2)
			m=max(m,i);
	}
	printf("%d\n",m);
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int i,m,p,q,t1,t2;

inline bool check1(int x)
{
	if (x==1)
		return false;
	for (int i=2;i*i<=x;i++)
		if (! (x%i))
			return false;
	return true;
}

inline bool check2(int x)
{
	char c[10];
	c[0]=0;
	for (;x;x=x/10)
		c[0]++,c[c[0]]=x%10;
	for (int i=1;i<=c[0];i++)
		if (c[i]!=c[c[0]+1-i])
			return false;
	return true;
}

int main()
{
	scanf("%d%d",&p,&q);
	for (i=1;i<=1200000;i++)
	{
		if (check1(i))
			t1++;
		if (check2(i))
			t2++;
		if (1LL*q*t1<=1LL*p*t2)
			m=max(m,i);
	}
	if (m)
		printf("%d\n",m);
	else
		printf("Palindromic tree is better than splay tree\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10000000;
typedef long long LL;
bool flag[MAXN + 100];

bool hws(int c){
    static int num[10];
    int top = 0;
    do{
	num[++top] = c % 10;
	c /= 10;
    }while(c);

    for(int l = 1,r = top;l < r; ++l, --r){
	if(num[l] != num[r]) return false;
    }
    return true;
}
int main(){
    if(fopen("input.txt","r")){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    }

    int p, q;
    scanf("%d%d", &p, &q);

    int zs = 0,hw = 0, ans = -1;

    flag[1] = true;
    for(int i = 1;i <= MAXN; ++i){
	if(zs * q <= p * hw){
	    ans = i;
	}

	if(!flag[i]) {
	    //    printf("%d ", i);
	    zs++;
	    for(int j = i * 2;j <= MAXN; j += i)
		flag[j] = true;
	}

	if(hws(i)) hw++;
	//	printf("%d %d %d\n",i, hw, zs);
    }

    if(ans != -1)
	printf("%d\n", ans - 1);
    else
	puts("Palindromic tree is better than splay tree");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
typedef long long LL;
bool flag[MAXN + 100];

bool hws(int c){
    static int num[10];
    int top = 0;
    do{
	num[++top] = c % 10;
	c /= 10;
    }while(c);

    for(int l = 1,r = top;l < r; ++l, --r){
	if(num[l] != num[r]) return false;
    }
    return true;
}
int main(){
    if(fopen("input.txt","r")){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    }

    int p, q;
    scanf("%d%d", &p, &q);

    int zs = 0,hw = 0, ans = -1;

    flag[1] = true;
    for(int i = 1;i <= MAXN; ++i){
	if(zs * q <= p * hw){
	    ans = i;
	}

	if(!flag[i]) {
	    //    printf("%d ", i);
	    zs++;
	    for(int j = i * 2;j <= MAXN; j += i)
		flag[j] = true;
	}

	if(hws(i)) hw++;
	//	printf("%d %d %d\n",i, hw, zs);
    }

    if(ans != -1)
	printf("%d\n", ans - 1);
    else
	puts("Palindromic tree is better than splay tree");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10000000;
typedef long long LL;
bool flag[MAXN + 100];

bool hws(int c){
    static int num[10];
    int top = 0;
    do{
	num[++top] = c % 10;
	c /= 10;
    }while(c);

    for(int l = 1,r = top;l < r; ++l, --r){
	if(num[l] != num[r]) return false;
    }
    return true;
}
int main(){
    if(fopen("input.txt","r")){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    }

    LL p, q;
    scanf("%I64d%I64d", &p, &q);

    LL zs = 0,hw = 0;
    int ans = -1;

    flag[1] = true;
    for(int i = 1;i <= MAXN; ++i){
	if(zs * q <= p * hw){
	    ans = i;
	}

	if(!flag[i]) {
	    //    printf("%d ", i);
	    zs++;
	    for(int j = i * 2;j <= MAXN; j += i)
		flag[j] = true;
	}

	if(hws(i)) hw++;
	//	printf("%d %d %d\n",i, hw, zs);
    }

    if(ans != -1)
	printf("%d\n", ans - 1);
    else
	puts("Palindromic tree is better than splay tree");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100000000;
typedef long long LL;
bool flag[MAXN + 100];

bool hws(int c){
    static int num[10];
    int top = 0;
    do{
	num[++top] = c % 10;
	c /= 10;
    }while(c);

    for(int l = 1,r = top;l < r; ++l, --r){
	if(num[l] != num[r]) return false;
    }
    return true;
}
int main(){
    if(fopen("input.txt","r")){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    }

    int p, q;
    scanf("%d%d", &p, &q);

    int zs = 0,hw = 0, ans = -1;

    flag[1] = true;
    for(int i = 1;i <= MAXN; ++i){
	if(zs * q <= p * hw){
	    ans = i;
	}

	if(!flag[i]) {
	    //    printf("%d ", i);
	    zs++;
	    for(int j = i * 2;j <= MAXN; j += i)
		flag[j] = true;
	}

	if(hws(i)) hw++;
	//	printf("%d %d %d\n",i, hw, zs);
    }

    if(ans != -1)
	printf("%d\n", ans - 1);
    else
	puts("Palindromic tree is better than splay tree");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10000000;
typedef long long LL;
bool flag[MAXN + 100];

bool hws(int c){
    static int num[10];
    int top = 0;
    do{
	num[++top] = c % 10;
	c /= 10;
    }while(c);

    for(int l = 1,r = top;l < r; ++l, --r){
	if(num[l] != num[r]) return false;
    }
    return true;
}
int main(){
    if(fopen("input.txt","r")){
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    }

    LL p, q;
    scanf("%lld%lld", &p, &q);

    LL zs = 0,hw = 0;
    int ans = -1;

    flag[1] = true;
    for(int i = 1;i <= MAXN; ++i){
	if(zs * q <= p * hw){
	    ans = i;
	}

	if(!flag[i]) {
	    //    printf("%d ", i);
	    zs++;
	    for(int j = i * 2;j <= MAXN; j += i)
		flag[j] = true;
	}

	if(hws(i)) hw++;
	//	printf("%d %d %d\n",i, hw, zs);
    }

    if(ans != -1)
	printf("%d\n", ans - 1);
    else
	puts("Palindromic tree is better than splay tree");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define RepP(i,n) for(int i = 1; i <= (n); i++) //Repeat Pascal style
#define RepdP(i, n) for(int i = n; i > 0; i--) //Repeat backward Pascal style
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define var(a, b) typeof(b) a(b)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define last(a) (sz(a) - 1)
#define ms(a,x) memset(a, x, sizeof(a))
#define Exist(a, b) (find(all(a), (b)) != (a).end())
#define Sort(a) sort(all(a))
#define Gsort(a) sort(all(a), greater<typeof(*((a).begin()))>())
#define Unique(a) Sort(a); (a).resize(unique(all(a)) - (a).begin())
#define Enum(a) Fit(it, (a)) cout << *it << " "; cout << endl;
#define el '\n'
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)

template<class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; }
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return s == 0 ? 0 : cntbit(s >> 1) + (s & 1); }

const ld PI = acos(-1.0);
const ld eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
const ll M = (ll)1e8 + 7;
void disp(int arr[], int narr){
    For(i,1,narr) cout << arr[i] << " ";
    cout << el;
}
void disp(vector<int> v){
    int nv = v.size(), nn = min(nv, 15);
    For(i,0,nn - 1) cout << v[i] << " ";
    cout << el;
}
// paste source code========================================================
ll p[M]; int maxP = 1e7; int cnt; // p[cnt-1] < maxP, maxP ~ 5e6 thi chay ngon
bool cp[M];
void setPrimeArray(){
    cnt = 1;
    cp[1] = false;
    For(i,2,maxP) cp[i] = true;
    For(i,2,maxP){
        if(cp[i]){
            p[cnt] = i; cnt ++;
            for(int j = 2 * i; j <= maxP; j += i) cp[j] = false;
        }
    }
}
// declare ========================================================
int a[M], c[M], qq, pp, ans;
bool b[M];

// create function========================================================
bool checkP(int n){
    int x[10], nx = 0;
    while(n > 0){
        nx++;
        x[nx] = n % 10;
        n /= 10;
    }
    For(i,1,nx/2) if(x[i] != x[nx + 1 - i]) return false;
    return true;
}
void init(){
    setPrimeArray();
    For(i,1,cnt - 1){
        a[p[i]] = i;
    }
    For(i,2,maxP){
        if(a[i] == 0) a[i] = a[i-1];
    }
    For(i,1,maxP) if(checkP(i)) b[i] = 1;
    For(i,1,maxP) if(b[i]) c[i] = c[i-1] + 1;
        else c[i] = c[i-1];
    //disp(c, 12);
    //cout << cnt << el;
}

int sol(){
    //initialize array, vector, .........................
    cin >> pp >> qq;

    //solve...............................................
    For(i,1,maxP){
        if(a[i] * qq <= c[i] * pp) ans = i;
    }
    //display result......................................
    cout << ans << el;
}
int xtest = 1;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	#endif
	std::ios::sync_with_stdio(false);
	init();
    while(xtest--)  sol();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define RepP(i,n) for(int i = 1; i <= (n); i++) //Repeat Pascal style
#define RepdP(i, n) for(int i = n; i > 0; i--) //Repeat backward Pascal style
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define var(a, b) typeof(b) a(b)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define last(a) (sz(a) - 1)
#define ms(a,x) memset(a, x, sizeof(a))
#define Exist(a, b) (find(all(a), (b)) != (a).end())
#define Sort(a) sort(all(a))
#define Gsort(a) sort(all(a), greater<typeof(*((a).begin()))>())
#define Unique(a) Sort(a); (a).resize(unique(all(a)) - (a).begin())
#define Enum(a) Fit(it, (a)) cout << *it << " "; cout << endl;
#define el '\n'
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)

template<class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; }
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return s == 0 ? 0 : cntbit(s >> 1) + (s & 1); }

const ld PI = acos(-1.0);
const ld eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
const int M = 1e7 + 7;
void disp(int arr[], int narr){
    For(i,1,narr) cout << arr[i] << " ";
    cout << el;
}
void disp(vector<int> v){
    int nv = v.size(), nn = min(nv, 15);
    For(i,0,nn - 1) cout << v[i] << " ";
    cout << el;
}
// paste source code========================================================
int p[M]; int maxP = 1e7; int cnt; // p[cnt-1] < maxP, maxP ~ 5e6 thi chay ngon
bool cp[M];
void setPrimeArray(){
    cnt = 1;
    cp[1] = false;
    For(i,2,maxP) cp[i] = true;
    For(i,2,maxP){
        if(cp[i]){
            p[cnt] = i; cnt ++;
            for(int j = 2 * i; j <= maxP; j += i) cp[j] = false;
        }
    }
}
// declare ========================================================
int a[M], c[M], ans;
ll pp, qq;
bool b[M];

// create function========================================================
int x[10], nx;
bool checkP(int n){
    nx = 0;
    while(n > 0){
        nx++;
        x[nx] = n % 10;
        n /= 10;
    }
    For(i,1,nx/2) if(x[i] != x[nx + 1 - i]) return false;
    return true;
}
void init(){
    setPrimeArray();
    For(i,1,cnt - 1){
        a[p[i]] = i;
    }
    For(i,2,maxP){
        if(a[i] == 0) a[i] = a[i-1];
    }
    For(i,1,maxP) if(checkP(i)) b[i] = 1;
    For(i,1,maxP) if(b[i]) c[i] = c[i-1] + 1;
        else c[i] = c[i-1];
    //disp(c, 12);
    //cout << cnt << el;
}

int sol(){
    //initialize array, vector, .........................
    cin >> pp >> qq;

    //solve...............................................
    int x = 0;
    For(i,1,maxP){
        if((ll) a[i] * qq <= (ll) c[i] * pp) ans = i;
        //if(a[i] >= 42 * c[i] && x == 0) x = i;
    }
    //display result......................................
    cout << ans << el;
    //cout << x << el;
}
int xtest = 1;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	#endif
	std::ios::sync_with_stdio(false);
	init();
    while(xtest--)  sol();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define RepP(i,n) for(int i = 1; i <= (n); i++) //Repeat Pascal style
#define RepdP(i, n) for(int i = n; i > 0; i--) //Repeat backward Pascal style
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define var(a, b) typeof(b) a(b)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define last(a) (sz(a) - 1)
#define ms(a,x) memset(a, x, sizeof(a))
#define Exist(a, b) (find(all(a), (b)) != (a).end())
#define Sort(a) sort(all(a))
#define Gsort(a) sort(all(a), greater<typeof(*((a).begin()))>())
#define Unique(a) Sort(a); (a).resize(unique(all(a)) - (a).begin())
#define Enum(a) Fit(it, (a)) cout << *it << " "; cout << endl;
#define el '\n'
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)

template<class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; }
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return s == 0 ? 0 : cntbit(s >> 1) + (s & 1); }

const ld PI = acos(-1.0);
const ld eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
const int M = 5e7 + 7;
void disp(int arr[], int narr){
    For(i,1,narr) cout << arr[i] << " ";
    cout << el;
}
void disp(vector<int> v){
    int nv = v.size(), nn = min(nv, 15);
    For(i,0,nn - 1) cout << v[i] << " ";
    cout << el;
}
// paste source code========================================================
int p[M]; int maxP = 1e7; int cnt; // p[cnt-1] < maxP, maxP ~ 5e6 thi chay ngon
bool cp[M];
void setPrimeArray(){
    cnt = 1;
    cp[1] = false;
    For(i,2,maxP) cp[i] = true;
    For(i,2,maxP){
        if(cp[i]){
            p[cnt] = i; cnt ++;
            for(int j = 2 * i; j <= maxP; j += i) cp[j] = false;
        }
    }
}
// declare ========================================================
int a[M], c[M], qq, pp, ans;
bool b[M];

// create function========================================================
int x[10], nx;
bool checkP(int n){
    nx = 0;
    while(n > 0){
        nx++;
        x[nx] = n % 10;
        n /= 10;
    }
    For(i,1,nx/2) if(x[i] != x[nx + 1 - i]) return false;
    return true;
}
void init(){
    setPrimeArray();
    For(i,1,cnt - 1){
        a[p[i]] = i;
    }
    For(i,2,maxP){
        if(a[i] == 0) a[i] = a[i-1];
    }
    For(i,1,maxP) if(checkP(i)) b[i] = 1;
    For(i,1,maxP) if(b[i]) c[i] = c[i-1] + 1;
        else c[i] = c[i-1];
    //disp(c, 12);
    //cout << cnt << el;
}

int sol(){
    //initialize array, vector, .........................
    cin >> pp >> qq;

    //solve...............................................
    For(i,1,maxP){
        if(a[i] * qq <= c[i] * pp) ans = i;
    }
    //display result......................................
    cout << ans << el;
}
int xtest = 1;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	#endif
	std::ios::sync_with_stdio(false);
	init();
    while(xtest--)  sol();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define RepP(i,n) for(int i = 1; i <= (n); i++) //Repeat Pascal style
#define RepdP(i, n) for(int i = n; i > 0; i--) //Repeat backward Pascal style
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define var(a, b) typeof(b) a(b)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define last(a) (sz(a) - 1)
#define ms(a,x) memset(a, x, sizeof(a))
#define Exist(a, b) (find(all(a), (b)) != (a).end())
#define Sort(a) sort(all(a))
#define Gsort(a) sort(all(a), greater<typeof(*((a).begin()))>())
#define Unique(a) Sort(a); (a).resize(unique(all(a)) - (a).begin())
#define Enum(a) Fit(it, (a)) cout << *it << " "; cout << endl;
#define el '\n'
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)

template<class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; }
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return s == 0 ? 0 : cntbit(s >> 1) + (s & 1); }

const ld PI = acos(-1.0);
const ld eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
const int M = 1e7 + 7;
void disp(int arr[], int narr){
    For(i,1,narr) cout << arr[i] << " ";
    cout << el;
}
void disp(vector<int> v){
    int nv = v.size(), nn = min(nv, 15);
    For(i,0,nn - 1) cout << v[i] << " ";
    cout << el;
}
// paste source code========================================================
int p[M]; int maxP = 1e7; int cnt; // p[cnt-1] < maxP, maxP ~ 5e6 thi chay ngon
bool cp[M];
void setPrimeArray(){
    cnt = 1;
    cp[1] = false;
    For(i,2,maxP) cp[i] = true;
    For(i,2,maxP){
        if(cp[i]){
            p[cnt] = i; cnt ++;
            for(int j = 2 * i; j <= maxP; j += i) cp[j] = false;
        }
    }
}
// declare ========================================================
int a[M], c[M], qq, pp, ans;
bool b[M];

// create function========================================================
int x[10], nx;
bool checkP(int n){
    nx = 0;
    while(n > 0){
        nx++;
        x[nx] = n % 10;
        n /= 10;
    }
    For(i,1,nx/2) if(x[i] != x[nx + 1 - i]) return false;
    return true;
}
void init(){
    setPrimeArray();
    For(i,1,cnt - 1){
        a[p[i]] = i;
    }
    For(i,2,maxP){
        if(a[i] == 0) a[i] = a[i-1];
    }
    For(i,1,maxP) if(checkP(i)) b[i] = 1;
    For(i,1,maxP) if(b[i]) c[i] = c[i-1] + 1;
        else c[i] = c[i-1];
    //disp(c, 12);
    //cout << cnt << el;
}

int sol(){
    //initialize array, vector, .........................
    cin >> pp >> qq;

    //solve...............................................
    For(i,1,maxP){
        if(a[i] * qq <= c[i] * pp) ans = i;
    }
    //display result......................................
    cout << ans << el;
}
int xtest = 1;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	#endif
	std::ios::sync_with_stdio(false);
	init();
    while(xtest--)  sol();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define RepP(i,n) for(int i = 1; i <= (n); i++) //Repeat Pascal style
#define RepdP(i, n) for(int i = n; i > 0; i--) //Repeat backward Pascal style
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define var(a, b) typeof(b) a(b)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define last(a) (sz(a) - 1)
#define ms(a,x) memset(a, x, sizeof(a))
#define Exist(a, b) (find(all(a), (b)) != (a).end())
#define Sort(a) sort(all(a))
#define Gsort(a) sort(all(a), greater<typeof(*((a).begin()))>())
#define Unique(a) Sort(a); (a).resize(unique(all(a)) - (a).begin())
#define Enum(a) Fit(it, (a)) cout << *it << " "; cout << endl;
#define el '\n'
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)

template<class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; }
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return s == 0 ? 0 : cntbit(s >> 1) + (s & 1); }

const ld PI = acos(-1.0);
const ld eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
const int M = 5e7 + 7;
void disp(int arr[], int narr){
    For(i,1,narr) cout << arr[i] << " ";
    cout << el;
}
void disp(vector<int> v){
    int nv = v.size(), nn = min(nv, 15);
    For(i,0,nn - 1) cout << v[i] << " ";
    cout << el;
}
// paste source code========================================================
ll p[M]; int maxP = 1e7; int cnt; // p[cnt-1] < maxP, maxP ~ 5e6 thi chay ngon
bool cp[M];
void setPrimeArray(){
    cnt = 1;
    cp[1] = false;
    For(i,2,maxP) cp[i] = true;
    For(i,2,maxP){
        if(cp[i]){
            p[cnt] = i; cnt ++;
            for(int j = 2 * i; j <= maxP; j += i) cp[j] = false;
        }
    }
}
// declare ========================================================
int a[M], c[M], qq, pp, ans;
bool b[M];

// create function========================================================
bool checkP(int n){
    int x[10], nx = 0;
    while(n > 0){
        nx++;
        x[nx] = n % 10;
        n /= 10;
    }
    For(i,1,nx/2) if(x[i] != x[nx + 1 - i]) return false;
    return true;
}
void init(){
    setPrimeArray();
    For(i,1,cnt - 1){
        a[p[i]] = i;
    }
    For(i,2,maxP){
        if(a[i] == 0) a[i] = a[i-1];
    }
    For(i,1,maxP) if(checkP(i)) b[i] = 1;
    For(i,1,maxP) if(b[i]) c[i] = c[i-1] + 1;
        else c[i] = c[i-1];
    //disp(c, 12);
    //cout << cnt << el;
}

int sol(){
    //initialize array, vector, .........................
    cin >> pp >> qq;

    //solve...............................................
    For(i,1,maxP){
        if(a[i] * qq <= c[i] * pp) ans = i;
    }
    //display result......................................
    cout << ans << el;
}
int xtest = 1;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	#endif
	std::ios::sync_with_stdio(false);
	init();
    while(xtest--)  sol();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;

#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define RepP(i,n) for(int i = 1; i <= (n); i++) //Repeat Pascal style
#define RepdP(i, n) for(int i = n; i > 0; i--) //Repeat backward Pascal style
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define Fit(i,v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define Fitd(i,v) for(__typeof((v).rbegin()) i = (v).rbegin(); i != (v).rend(); ++i)
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define var(a, b) typeof(b) a(b)
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define last(a) (sz(a) - 1)
#define ms(a,x) memset(a, x, sizeof(a))
#define Exist(a, b) (find(all(a), (b)) != (a).end())
#define Sort(a) sort(all(a))
#define Gsort(a) sort(all(a), greater<typeof(*((a).begin()))>())
#define Unique(a) Sort(a); (a).resize(unique(all(a)) - (a).begin())
#define Enum(a) Fit(it, (a)) cout << *it << " "; cout << endl;
#define el '\n'
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)

template<class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; }
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> T sqr(T x) { return x * x; }
template<class T> T cube(T x) { return x * x * x; }
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return s == 0 ? 0 : cntbit(s >> 1) + (s & 1); }

const ld PI = acos(-1.0);
const ld eps = 1e-9;
const int dr[] = {-1, 0, +1, 0};
const int dc[] = {0, +1, 0, -1};
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll mod = (ll)1e9 + 7;
const int M = 5e7 + 7;
void disp(int arr[], int narr){
    For(i,1,narr) cout << arr[i] << " ";
    cout << el;
}
void disp(vector<int> v){
    int nv = v.size(), nn = min(nv, 15);
    For(i,0,nn - 1) cout << v[i] << " ";
    cout << el;
}
// paste source code========================================================
int p[M]; int maxP = 1e7; int cnt; // p[cnt-1] < maxP, maxP ~ 5e6 thi chay ngon
bool cp[M];
void setPrimeArray(){
    cnt = 1;
    cp[1] = false;
    For(i,2,maxP) cp[i] = true;
    For(i,2,maxP){
        if(cp[i]){
            p[cnt] = i; cnt ++;
            for(int j = 2 * i; j <= maxP; j += i) cp[j] = false;
        }
    }
}
// declare ========================================================
int a[M], c[M], qq, pp, ans;
bool b[M];

// create function========================================================
bool checkP(int n){
    int x[10], nx = 0;
    while(n > 0){
        nx++;
        x[nx] = n % 10;
        n /= 10;
    }
    For(i,1,nx/2) if(x[i] != x[nx + 1 - i]) return false;
    return true;
}
void init(){
    setPrimeArray();
    For(i,1,cnt - 1){
        a[p[i]] = i;
    }
    For(i,2,maxP){
        if(a[i] == 0) a[i] = a[i-1];
    }
    For(i,1,maxP) if(checkP(i)) b[i] = 1;
    For(i,1,maxP) if(b[i]) c[i] = c[i-1] + 1;
        else c[i] = c[i-1];
    //disp(c, 12);
    //cout << cnt << el;
}

int sol(){
    //initialize array, vector, .........................
    cin >> pp >> qq;

    //solve...............................................
    For(i,1,maxP){
        if(a[i] * qq <= c[i] * pp) ans = i;
    }
    //display result......................................
    cout << ans << el;
}
int xtest = 1;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	#endif
	std::ios::sync_with_stdio(false);
	init();
    while(xtest--)  sol();
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include<stdio.h>
using namespace std;
const int MAX = 3e6;
int ar[MAX];bool pr[MAX];
string s;
void pre(){
    pr[0] = 1;
    pr[1] = 1;
    for(int i=2;i*i<MAX;++i){
        if(!pr[i]){
            for(int j=i*i;j<MAX;j+=i){
                pr[j] = 1;
            }
        }
    }
}
int ste(int n){
    int x = 0;
    int r;
    s = "";
    while(n){
        r = n%10;
        s += (r + '0');
        n /= 10;
        ++x;
    }
    // cout<<s<<endl;
    return x;
}
bool pal(int x){
    int len = ste(x);
    for(int i=0;i<len/2;++i)if(s[i] != s[len-i-1])return false;
    return true;
}
int main(){
    int p,q;
    pre();
    scanf("%d%d",&p,&q);
    int ispr = 0;
    int ispal = 0;
    int ans = -1;
    for(int i=1;i<MAX;++i){
        if(!pr[i]){
            ispr++;
        }
        if(pal(i)){
            ispal++;
        }
        if(1LL*ispal*q >= 1LL*ispr*p){
            ans = i;
        }
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include<stdio.h>
using namespace std;
const int MAX = 3e6;
int ar[MAX];bool pr[MAX];
string s;
void pre(){
    pr[0] = 1;
    pr[1] = 1;
    for(int i=2;i*i<MAX;++i){
        if(!pr[i]){
            for(int j=i*i;j<MAX;j+=i){
                pr[j] = 1;
            }
        }
    }
}
int ste(int n){
    int x = 0;
    int r;
    s = "";
    while(n){
        r = n%10;
        s += (r + '0');
        n /= 10;
        ++x;
    }
    // cout<<s<<endl;
    return x;
}
bool pal(int x){
    int len = ste(x);
    for(int i=0;i<len/2;++i)if(s[i] != s[len-i-1])return false;
    return true;
}
int main(){
    int p,q;
    pre();
    scanf("%d%d",&p,&q);
    int ispr = 0;
    int ispal = 0;
    int ans = -1;
    for(int i=1;i<MAX;++i){
        if(!pr[i]){
            ispr++;
        }
        if(pal(i)){
            ispal++;
        }
        if(1LL*ispal*p >= 1LL*ispr*q){
            ans = i;
        }
    }
    cout<<ans<<endl;
}


#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
const int MAX = 3e6;
int ar[MAX];bool pr[MAX];
string s;
void pre(){
    pr[0] = 1;
    pr[1] = 1;
    for(int i=2;i*i<MAX;++i){
        if(!pr[i]){
            for(int j=i*i;j<MAX;j+=i){
                pr[j] = 1;
            }
        }
    }
}
int ste(int n){
    int x = 0;
    int r;
    s = "";
    while(n){
        r = n%10;
        s += (r + '0');
        n /= 10;
        ++x;
    }
    // cout<<s<<endl;
    return x;
}
bool pal(int x){
    int len = ste(x);
    for(int i=0;i<len/2;++i)if(s[i] != s[len-i-1])return false;
    return true;
}
int main(){
    int p,q;
    pre();
    scanf("%d%d",&p,&q);
    int ispr = 0;
    int ispal = 0;
    int ans = -1;
    for(int i=1;i<MAX;++i){
        if(!pr[i]){
            ispr++;
        }
        if(pal(i)){
            ispal++;
        }
        if(1LL*ispal*q >= 1LL*ispr*p){
            ans = i;
        }
    }
    cout<<ans<<endl;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<stack>
#include<map>
#include<set>
#include<string.h>
#include<math.h>
#define MOD 1000000007
#define MIN -100000000
#define MAX 100000000
#define ll long long int
template<class T>T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template<class T>T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T>T powmod(T a,T b) {T res=1;if(a>=MOD)a%=MOD;for(;b;b>>=1){if(b&1)res=res*a;if(res>=MOD)res%=MOD;a=a*a;if(a>=MOD)a%=MOD;}return res;}

/* HOPE n WILL :)
    NGU :)
    _/\_    */
// MG

int a[10000005];
int pal(int num)
{
    int t1=num;
    int nnum=0;
    while(num!=0)
    {
        nnum=nnum*10;
        nnum=nnum+num%10;
        num/=10;
    }
    if(nnum==t1)
    return 1;
    else return 0;
}
int main()
{
    int n,i,j,p,q;
    for(i=4;i<10000005;i+=2)
    a[i]=1;
    for(i=3;i<=sqrt(10000001);i+=2)
    {
        if(a[i]==0)
        {
            for(j=i*i;j<=10000005;j=j+2*i)
            a[j]=1;
        }
    }
    int pr=0;
    int palin=0;
    int ans;
    a[1]=1;
    scanf("%d %d",&p,&q);
    for(i=1;i<=10000005;i++)
    {
        if(a[i]==0)
        pr++;
        if(pal(i)==1)
        palin++;
        if(p*palin>=q*pr)
        {
            ans=i;
        }
    }
    //cout<<pr<<" "<<palin;

    cout<<ans<<"\n";
    return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<stack>
#include<map>
#include<set>
#include<string.h>
#include<math.h>
#define MOD 1000000007
#define MIN -100000000
#define MAX 100000000
#define ll long long int
template<class T>T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template<class T>T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T>T powmod(T a,T b) {T res=1;if(a>=MOD)a%=MOD;for(;b;b>>=1){if(b&1)res=res*a;if(res>=MOD)res%=MOD;a=a*a;if(a>=MOD)a%=MOD;}return res;}

/* HOPE n WILL :)
    NGU :)
    _/\_    */
// MG

int a[10000005];
int pal(int num)
{
    int t1=num;
    int nnum=0;
    while(num!=0)
    {
        nnum=nnum*10;
        nnum=nnum+num%10;
        num/=10;
    }
    if(nnum==t1)
    return 1;
    else return 0;
}
int main()
{
    int n,i,j,p,q;
    for(i=4;i<10000005;i+=2)
    a[i]=1;
    for(i=3;i<=sqrt(10000001);i+=2)
    {
        if(a[i]==0)
        {
            for(j=i*i;j<=10000005;j=j+2*i)
            a[j]=1;
        }
    }
    int pr=0;
    int palin=0;
    int ans;
    a[1]=1;
    scanf("%d %d",&p,&q);
    for(i=1;i<=2000005;i++)
    {
        if(a[i]==0)
        pr++;
        if(pal(i)==1)
        palin++;
        if(p*palin>=q*pr)
        {
            ans=i;
        }
    }
    //cout<<pr<<" "<<palin;

    cout<<ans<<"\n";
    return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<stack>
#include<map>
#include<set>
#include<string.h>
#include<math.h>
#define MOD 1000000007
#define MIN -100000000
#define MAX 100000000
#define ll long long int
template<class T>T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template<class T>T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T>T powmod(T a,T b) {T res=1;if(a>=MOD)a%=MOD;for(;b;b>>=1){if(b&1)res=res*a;if(res>=MOD)res%=MOD;a=a*a;if(a>=MOD)a%=MOD;}return res;}

/* HOPE n WILL :)
    NGU :)
    _/\_    */
// MG

int a[1000005];
int pal(int num)
{
    int t1=num;
    int nnum=0;
    while(num!=0)
    {
        nnum=nnum*10;
        nnum=nnum+num%10;
        num/=10;
    }
    if(nnum==t1)
    return 1;
    else return 0;
}
int main()
{
    int n,i,j,p,q;
    for(i=4;i<1000005;i+=2)
    a[i]=1;
    for(i=3;i<=1000;i+=2)
    {
        if(a[i]==0)
        {
            for(j=i*i;j<=1000005;j=j+2*i)
            a[j]=1;
        }
    }
    int pr=0;
    int palin=0;
    int ans;
    a[1]=1;
    scanf("%d %d",&p,&q);
    for(i=1;i<=1000005;i++)
    {
        if(a[i]==0)
        pr++;
        if(pal(i)==1)
        palin++;
        if(p*palin>=q*pr)
        {
            ans=i;
        }
    }
    //cout<<pr<<" "<<palin;

    cout<<ans<<"\n";
    return 0;
}


#include<iostream>
using namespace std;
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<utility>
#include<stack>
#include<map>
#include<set>
#include<string.h>
#include<math.h>
#define MOD 1000000007
#define MIN -100000000
#define MAX 100000000
#define ll long long int
template<class T>T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template<class T>T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T>T powmod(T a,T b) {T res=1;if(a>=MOD)a%=MOD;for(;b;b>>=1){if(b&1)res=res*a;if(res>=MOD)res%=MOD;a=a*a;if(a>=MOD)a%=MOD;}return res;}

/* HOPE n WILL :)
    NGU :)
    _/\_    */
// MG

int a[10000005];
int pal(int num)
{
    int t1=num;
    int nnum=0;
    while(num!=0)
    {
        nnum=nnum*10;
        nnum=nnum+num%10;
        num/=10;
    }
    if(nnum==t1)
    return 1;
    else return 0;
}
int main()
{
    int n,i,j,p,q;
    for(i=4;i<10000005;i+=2)
    a[i]=1;
    for(i=3;i<=sqrt(10000001);i+=2)
    {
        if(a[i]==0)
        {
            for(j=i*i;j<=10000005;j=j+2*i)
            a[j]=1;
        }
    }
    int pr=0;
    int palin=0;
    int ans;
    a[1]=1;
    scanf("%d %d",&p,&q);
    for(i=1;i<=10000001;i++)
    {
        if(a[i]==0)
        pr++;
        if(pal(i)==1)
        palin++;
        if(p*palin>=q*pr)
        {
            ans=i;
        }
    }
    //cout<<pr<<" "<<palin;

    cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define mp make_pair
#define pb push_back
#define pf push_front

#define M 1000007

using namespace std;

typedef long long ll;

bool isPrime[M];

void seive(){
	isPrime[1] = false;
	for(int i=2; i<M/2; i++){
		if(!isPrime[i]){continue;}
		for(int j=2; i*j<1000007; j++){
			isPrime[i*j] = false;
		}
	}
}

bool isPal(int n){
	int temp = n;
	int newInt = 0;
	while(temp){
		newInt *= 10;
		newInt += temp%10;
		temp /= 10;
	}
	return (newInt==n);
}

int main(){
	memset(isPrime, 1, sizeof(isPrime));
	seive();
	// for(int i=1; i<M; i++){
	// 	if(isPrime[i]){cout<<i<<endl;}
	// }
	int primesLess[M];
	primesLess[1] = 0;
	for(int i=2; i<M; i++){
		primesLess[i] = primesLess[i-1];
		if(isPrime[i]){primesLess[i]++;}
	}
	int palindromeLess[M];
	palindromeLess[1] = 1;
	for(int i=2; i<M; i++){
		palindromeLess[i] = palindromeLess[i-1];
		if(isPal(i)){palindromeLess[i]++;}
	}
	float p,q;
	cin>>p>>q;
	float value = p/q;
	int maxAns  =  -1;
	for(int i=1; i<M; i++){
		double primeCount = primesLess[i];
		double palCount = palindromeLess[i];
		if( primeCount <= value*palCount){
			maxAns = i;
			// return 0;
		}
	}
	cout<<maxAns<<endl;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define mp make_pair
#define pb push_back
#define pf push_front

#define M 10000000

using namespace std;

typedef long long ll;

bool isPrime[M];

void seive(){
	isPrime[1] = false;
	for(int i=2; i<M/2; i++){
		if(!isPrime[i]){continue;}
		for(int j=2; i*j<M; j++){
			isPrime[i*j] = false;
		}
	}
}

bool isPal(int n){
	int temp = n;
	int newInt = 0;
	while(temp){
		newInt *= 10;
		newInt += temp%10;
		temp /= 10;
	}
	return (newInt==n);
}

int primesLess[M];
int palindromeLess[M];

int main(){
	ios_base::sync_with_stdio(false);
	memset(isPrime, 1, sizeof(isPrime));
	seive();
	// for(int i=1; i<M; i++){
	// 	if(isPrime[i]){cout<<i<<endl;}
	// }
	primesLess[1] = 0;
	for(int i=2; i<M; i++){
		primesLess[i] = primesLess[i-1];
		if(isPrime[i]){primesLess[i]++;}
	}
	palindromeLess[1] = 1;
	for(int i=2; i<M; i++){
		palindromeLess[i] = palindromeLess[i-1];
		if(isPal(i)){palindromeLess[i]++;}
	}
	float p,q;
	cin>>p>>q;
	float value = p/q;
	int maxAns  =  -1;
	for(int i=1; i<M; i++){
		double primeCount = primesLess[i];
		double palCount = palindromeLess[i];
		if( primeCount <= value*palCount){
			maxAns = i;
			// return 0;
		}
	}
	if(maxAns==-1){
		cout<< "Palindromic tree is better than splay tree" <<endl;
		return 0;
	}
	cout<<maxAns<<endl;
	return 0;
	// cout<<maxAns<<endl;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define mp make_pair
#define pb push_back
#define pf push_front

#define M 2500000

using namespace std;

typedef long long ll;

bool isPrime[M];

void seive(){
	isPrime[1] = false;
	for(int i=2; i<M/2; i++){
		if(!isPrime[i]){continue;}
		for(int j=2; i*j<M; j++){
			isPrime[i*j] = false;
		}
	}
}

bool isPal(int n){
	int temp = n;
	int newInt = 0;
	while(temp){
		newInt *= 10;
		newInt += temp%10;
		temp /= 10;
	}
	return (newInt==n);
}

int primesLess[M];
int palindromeLess[M];

int main(){
	memset(isPrime, 1, sizeof(isPrime));
	seive();
	// for(int i=1; i<M; i++){
	// 	if(isPrime[i]){cout<<i<<endl;}
	// }
	primesLess[1] = 0;
	for(int i=2; i<M; i++){
		primesLess[i] = primesLess[i-1];
		if(isPrime[i]){primesLess[i]++;}
	}
	palindromeLess[1] = 1;
	for(int i=2; i<M; i++){
		palindromeLess[i] = palindromeLess[i-1];
		if(isPal(i)){palindromeLess[i]++;}
	}
	float p,q;
	cin>>p>>q;
	float value = p/q;
	int maxAns  =  -1;
	for(int i=1; i<M; i++){
		double primeCount = primesLess[i];
		double palCount = palindromeLess[i];
		if( primeCount <= value*palCount){
			maxAns = i;
			// return 0;
		}
	}
	if(maxAns==-1){
		cout<< "Palindromic tree is better than splay tree" <<endl;
		return 0;
	}
	cout<<maxAns<<endl;
	return 0;
	// cout<<maxAns<<endl;
}


#include <bits/stdc++.h>
#define pp pair<int, int>
#define mp make_pair
#define pb push_back
#define pf push_front

#define M 1000007

using namespace std;

typedef long long ll;

bool isPrime[M];

void seive(){
	isPrime[1] = false;
	for(int i=2; i<M/2; i++){
		if(!isPrime[i]){continue;}
		for(int j=2; i*j<1000007; j++){
			isPrime[i*j] = false;
		}
	}
}

bool isPal(int n){
	int temp = n;
	int newInt = 0;
	while(temp){
		newInt *= 10;
		newInt += temp%10;
		temp /= 10;
	}
	return (newInt==n);
}

int main(){
	memset(isPrime, 1, sizeof(isPrime));
	seive();
	// for(int i=1; i<M; i++){
	// 	if(isPrime[i]){cout<<i<<endl;}
	// }
	int primesLess[M];
	primesLess[1] = 0;
	for(int i=2; i<M; i++){
		primesLess[i] = primesLess[i-1];
		if(isPrime[i]){primesLess[i]++;}
	}
	int palindromeLess[M];
	palindromeLess[1] = 1;
	for(int i=2; i<M; i++){
		palindromeLess[i] = palindromeLess[i-1];
		if(isPal(i)){palindromeLess[i]++;}
	}
	float p,q;
	cin>>p>>q;
	float value = p/q;
	int maxAns  =  -1;
	for(int i=1; i<M; i++){
		double primeCount = primesLess[i];
		double palCount = palindromeLess[i];
		if( primeCount <= value*palCount){
			maxAns = i;
			// return 0;
		}
	}
	if(maxAns==-1){
		cout<< "Palindromic tree is better than splay tree" <<endl;
		return 0;
	}
	cout<<maxAns<<endl;
	return 0;
	// cout<<maxAns<<endl;
}


#include<bits/stdc++.h>
#define Int long long int
using namespace std;
const Int max_n = 1500000 + 5 ;
map <Int, bool> prime ;
Int i , j ;
Int pspm[ max_n ] , pspl[ max_n ] ;
bool pal( Int a )
{
   vector <int> pl , pk ;
   while( a > 0 )
      pl.push_back( a % 10 ) , a /= 10 ;
   pk = pl ;
   reverse( pl.begin() , pl.end() ) ;
   if( pk == pl )
      return true ;
   return false ;
}
int main()
{
   memset( pspm , 0 , sizeof( pspm ) ) ;
   memset( pspl , 0 , sizeof( pspl ) ) ;
   ios_base::sync_with_stdio(0) ;
   cin.tie(0) ;
   prime [ 1 ] = true ;
   for( i = 2 ; i < max_n ; i ++ )
      for( j = 2 ; j < max_n / i ; j ++ )
         prime[ i * j ] = true;
   for( i = 1 ; i < max_n ; i ++ )
   {
      pspm[ i ] += pspm[ i - 1 ] + ( !prime[ i ]  ) ;
      pspl[ i ] += pspl[ i - 1 ] + ( pal( i ) ) ;
   }
   Int p , q , pt  ;
   cin >> p >> q ;
   /*
      cout << pspm [ 40 ] << " " << pspl [ 40] << '\n' ;
   */
   for( pt = max_n ; pt >= 1 ; pt -- )
   {
      if( q * pspm[ pt ] <= p * pspl[ pt ] )
      {
         cout << pt ;
         return 0 ;
      }
   }
   cout << "Palindromic tree is better than splay tree" ;
   return 0 ;
}


#include<bits/stdc++.h>
#define Int long long int
using namespace std;
const Int max_n = 1000 * 100  ;
map <Int, bool> prime ;
Int i , j ;

bool pal( Int a )
{
   string b ;
   ostringstream convert ;
   convert.clear() ;
   convert << a ;
   b = convert.str();
   /*
      cout<< b << " " ;
   */
   Int l = b.length() ;
   for( i = 0 ; i< l / 2 ; i ++ )
      if( b[ i ] != b[ l - i - 1 ] )
         return false ;
   return true ;
}
int main()
{

   ios_base::sync_with_stdio(0) ;
   cin.tie(0) ;
   prime[ 1 ] = true ;
   for( i = 2 ; i < max_n ; i ++ )
      for( j = 2 ; j < max_n / i ; j ++ )
         prime[ i * j ] = true;
   Int p , q , pie = 0 , rub = 0 , pt = 1 , m = 0 ;
   cin >> p >> q ;
   while( pt < 1000 * 100 )
   {
      if( pal( pt ) )
         rub ++ ;
      if( ! prime[ pt ] )
         pie ++ ;
      if( q * pie <= p * rub )
         m = max( m , pt ) ;
      pt ++ ;
   }
   cout << m ;
   return 0 ;
}


#include<bits/stdc++.h>
#define Int long long int
using namespace std;
const Int max_n = 1500000 + 5 ;
map <Int, bool> prime ;
Int i , j ;
Int pspm[ max_n ] , pspl[ max_n ] ;
bool pal( Int a )
{
   vector <int> pl , pk ;
   while( a > 0 )
      pl.push_back( a % 10 ) , a /= 10 ;
   pk = pl ;
   reverse( pl.begin() , pl.end() ) ;
   if( pk == pl )
      return true ;
   return false ;
}
int main()
{
   ios_base::sync_with_stdio(0) ;
   cin.tie(0) ;
   prime [ 1 ] = true ;
   for( i = 2 ; i < max_n ; i ++ )
      if ( ! prime [ i ] )
         for( j = 2 ; j < max_n / i ; j ++ )
            prime[ i * j ] = true;

   for( i = 1 ; i < max_n ; i ++ )
   {
      pspm[ i ] += pspm[ i - 1 ] + ( !prime[ i ]  ) ;
      pspl[ i ] += pspl[ i - 1 ] + ( pal( i ) ) ;
   }
   Int p , q , pt  ;
   cin >> p >> q ;
   /*
      cout << pspm [ 40 ] << " " << pspl [ 40] << '\n' ;
   */
   for( pt = max_n ; pt >= 1 ; pt -- )
   {
      if( q * pspm [ pt ] <= p * pspl [ pt ] )
      {
         cout << pt ;
         return 0 ;
      }
   }
   cout << "Palindromic tree is better than splay tree" ;
   return 0 ;
}


#include<bits/stdc++.h>
#define Int long long int
using namespace std;
const Int max_n = 1000 * 1000  ;
map <Int, bool> prime ;
Int i , j ;

bool pal( Int a )
{
   string b ;
   ostringstream convert ;
   convert.clear() ;
   convert << a ;
   b = convert.str();
   /*
      cout<< b << " " ;
   */
   Int l = b.length() ;
   for( i = 0 ; i< l / 2 ; i ++ )
      if( b[ i ] != b[ l - i - 1 ] )
         return false ;
   return true ;
}
int main()
{

   ios_base::sync_with_stdio(0) ;
   cin.tie(0) ;
   prime[ 1 ] = true ;
   for( i = 2 ; i < max_n ; i ++ )
      for( j = 2 ; j < max_n / i ; j ++ )
         prime[ i * j ] = true;
   Int p , q , pie = 0 , rub = 0 , pt = 1 , m = 0 ;
   cin >> p >> q ;
   while( pt < 1000 * 1000 )
   {
      if( pal( pt ) )
         rub ++ ;
      if( ! prime[ pt ] )
         pie ++ ;
      if( q * pie <= p * rub )
         m = max( m , pt ) ;
      pt ++ ;
   }
   cout << m ;
   return 0 ;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 5e6+30;
int n,f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
    //printf("%d\n",f[N/2]);
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int ans = 0;
        for(int i=1;i<N;i++)if(p*c[i]-q*f[i]>=0){
                ans = max(ans,i);
        }
        if(ans == 0)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 3e7+30;
int n,f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
    //printf("%d\n",f[N/2]);
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int ans = 0;
        for(int i=1;i<N;i++)if(p*c[i]-q*f[i]>=0){
                ans = max(ans,i);
        }
        if(ans == 0)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 1e7+30;
int n;
long long f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
    //printf("%d\n",f[N/2]);
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int ans = 0;
        for(int i=1;i<N;i++)if(p*c[i]-q*f[i]>=0){
                ans = max(ans,i);
        }
        if(ans == 0)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 1e7+30;
int n,f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
    //printf("%d\n",f[N/2]);
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int ans = 0;
        for(int i=1;i<N;i++)if(p*c[i]-q*f[i]>=0){
                ans = max(ans,i);
        }
        if(ans == 0)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",ans);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 5e6+30;
int n,f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int l = 1,r = N-1;
        while(l<=r){
            int mid = (l+r)/2;
            if(-f[mid]*q+p*c[mid]>=0)
                l = mid+1;
            else r = mid-1;
        }
        if(r == -1)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",r);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 5e6+30;
int n,f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
    //printf("%d\n",f[N/2]);
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int l = 1,r = N-1;
        while(l<=r){
            int mid = (l+r)/2;
            if(-f[mid]*q+p*c[mid]>=0)
                l = mid+1;
            else r = mid-1;
        }
        if(r == 0)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",r);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cstring>
#include <vector>
using namespace std;

const int N = 5e6+30;
int n,f[N],c[N];
bool vis[N];
int is(int x)
{
    int num[10];
    int cnt = 0;
    while(x){
       num[cnt++] = x%10;
       x/=10;
    }
    for(int i=0,j=cnt-1;i<j;i++,j--)
        if(num[i]!=num[j])return 0;
    return 1;
}
void init()
{
    for(int i=2;i<N;i++)if(!vis[i]){
        for(int j=2*i;j<N;j+=i)
            vis[j] = true;
    }
    f[1] = 0;
    c[1] = 1;
    for(int i=2;i<N;i++){
        f[i] = f[i-1] + (vis[i]?0:1);
        c[i] = c[i-1] + is(i);
    }
    //printf("%d\n",f[N/2]);
}
int main()
{
    init();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF){
        int l = 1,r = N-1;
        int ans = 0;
        if(p>q){
            while(l<=r){
                int mid = (l+r)/2;
                if(-f[mid]*q+p*c[mid]>=0)
                    l = mid+1;
                else r = mid-1;
            }
            ans = r;
        }else {
           for(int i=1;i<N;i++)if(p*c[i]-q*f[i]<0){
                ans = i-1;
                break;
           }
        }
        if(ans == 0)printf("Palindromic tree is better than splay tree\n");
        else printf("%d\n",ans);

    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[1000];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		n=0;
		memset(str,0,sizeof str);
		while(x){
			str[n++]=x%10;
			x/=10;
		}
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[1000];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		n=0;
		memset(str,0,sizeof str);
		while(x){
			str[n++]=x%10+'0';
			x/=10;
		}
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

string str;

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		str.clear();
		while(x){
			str+=x%10;
			x/=10;
		}
		n=str.size();
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

string str;

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		str.clear();
		while(x){
			str+=x%10+'0';
			x/=10;
		}
		n=str.size();
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[1000];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		n=0;
		memset(str,0,sizeof str);
		while(x){
			str[n++]=x%10;
			x/=10;
		}
		reverse(str,str+n);
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[1000];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		n=0;
		memset(str,0,sizeof str);
		while(x){
			str[n++]=x%10+'0';
			x/=10;
		}
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(q*prinum<=p*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q,palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[10];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		n=0;
		while(x){
			str[n++]=x%10;
			x/=10;
		}
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

string str;

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		str.clear();
		while(x){
			str+=x%10+'0';
			x/=10;
		}
		n=str.size();
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(q*prinum<=p*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[1000];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		n=0;
		memset(str,0,sizeof str);
		while(x){
			str[n++]=x%10+'0';
			x/=10;
		}
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(q*prinum<=p*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

double p,q;
long long palnum,prinum;

long long int i,n,pal,ans,j,x;

bool H[2000001];

char str[1000];

int main(){

	H[1]=1;

	for(i=2 ; i<=2000000 ; i++)
		if(!H[i])
			for(j=i*i ; j<=2000000 ; j+=i)
				H[j]=1;

	cin>>p>>q;

	for(i=1 ; i<=2000000 ; i++){
		x=i;
		memset(str,0,sizeof str);
		n=sprintf(str,"%lld",i);
		pal=1;
		for(j=0 ; j<n/2 ; j++)
			if(str[j]!=str[n-j-1]){
				pal=0;
				break;
			}

		if(pal)
			palnum++;

		if(!H[i])
			prinum++;

		if(prinum<=p/q*palnum)
			ans=max(ans,i);
	}

	if(!ans)
		cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MaxN=2E6+10;
bool prime[MaxN],pal[MaxN];

bool find_prime(){
	prime[1]=false;
	for (int i=2;i<MaxN;++i)
		if (prime[i])
			for (int j=2*i;j<MaxN;j+=i)
				prime[j]=false;
}

bool check_pal(int n){
	int x=n,t=0;
	while (x){
		t*=10;
		t+=x%10;
		x/=10;
	}
	return (n==t);
}

int32_t main(){
	fill (prime,prime+MaxN,true);
	find_prime();
	for (int i=1;i<MaxN;++i)
		pal[i]=check_pal(i);
	int p,q;
	cin >> p >> q;
	int ans=0;
	int cnt_pal=0,cnt_prime=0;
	for (int i=1;i<MaxN;++i){
		cnt_pal+=pal[i];
		cnt_prime+=prime[i];
		if ((cnt_prime*q)<=(cnt_pal*p))
			ans=i;
	}
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MaxN=2E6+10;
bool prime[MaxN],pal[MaxN];

bool find_prime(){
	prime[1]=false;
	for (int i=2;i<MaxN;++i)
		if (prime[i])
			for (int j=2*i;j<MaxN;j+=i)
				prime[j]=false;
}

bool check_pal(int n){
	int x=n,t=0;
	while (x){
		t*=10;
		t+=x%10;
		x/=10;
	}
	return (n==t);
}

int32_t main(){
	fill (prime,prime+MaxN,true);
	find_prime();
	for (int i=1;i<MaxN;++i)
		pal[i]=check_pal(i);
	int p,q;
	cin >> p >> q;
	int ans=0;
	int cnt_pal=0,cnt_prime=0;
	for (int i=0;i<MaxN;++i){
		cnt_pal+=pal[i];
		cnt_prime+=prime[i];
		if (cnt_prime*p<=cnt_pal*q)
			ans=i;
	}
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MaxN=2E6+10;
bool prime[MaxN],pal[MaxN];

bool find_prime(){
	prime[1]=false;
	for (int i=2;i<MaxN;++i)
		if (prime[i])
			for (int j=2*i;j<MaxN;j+=i)
				prime[j]=false;
}

bool check_pal(int n){
	int x=n,t=0;
	while (x){
		t*=10;
		t+=x%10;
		x/=10;
	}
	return (n==t);
}

int32_t main(){
	fill (prime,prime+MaxN,true);
	find_prime();
	for (int i=1;i<MaxN;++i)
		pal[i]=check_pal(i);
	/*for (int i=1;i<=100;++i)
		cerr << pal[i] << " ";
	cerr << endl;
	for (int i=1;i<=100;++i)
		cerr << prime[i] << " ";
	cerr << endl;*/
	int p,q;
	cin >> p >> q;
	int ans=0;
	int cnt_pal=0,cnt_prime=0;
	for (int i=1;i<MaxN;++i){
		cnt_pal+=pal[i];
		cnt_prime+=prime[i];
		if ((1LL)*(cnt_prime*p)<=(1LL)*(cnt_pal*q))
			ans=i;
	}
	cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MaxN=2E6+10;
bool prime[MaxN],pal[MaxN];

bool find_prime(){
	prime[1]=false;
	for (int i=2;i<MaxN;++i)
		if (prime[i])
			for (int j=2*i;j<MaxN;j+=i)
				prime[j]=false;
}

bool check_pal(int n){
	int x=n,t=0;
	while (x){
		t*=10;
		t+=x%10;
		x/=10;
	}
	return (n==t);
}

int32_t main(){
	fill (prime,prime+MaxN,true);
	find_prime();
	for (int i=1;i<MaxN;++i)
		pal[i]=check_pal(i);
	/*for (int i=1;i<=100;++i)
		cerr << pal[i] << " ";
	cerr << endl;
	for (int i=1;i<=100;++i)
		cerr << prime[i] << " ";
	cerr << endl;*/
	int p,q;
	cin >> p >> q;
	int ans=0;
	int cnt_pal=0,cnt_prime=0;
	for (int i=1;i<MaxN;++i){
		cnt_pal+=pal[i];
		cnt_prime+=prime[i];
		if ((cnt_prime*p)<=(cnt_pal*q))
			ans=i;
	}
	cout << ans;
}


#include<bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) ((int)((x).size()))
#define IN(x,y) ((y).find((x)) != (y).end())
#define DBG(v) cerr<<#v<<" = "<<(v)<<endl;
#define FOREACH(i,t) for (typeof(t.begin()) i = t.begin(); i != t.end(); ++i)
#define fi first
#define se second

const int maxn = 1000000;
const int smaxn = 1000;

int sumpr[maxn+2];
bool pr[maxn+2];
bool pal[maxn+2];
int sumpal[maxn+2];

int main() {
	FORI(i,maxn) pr[i]=true;
	pr[1]=false;
	for (int i=2;i*i<maxn;i++) if (pr[i]) for (int j=i*i; j<maxn; j+=i) pr[j]=false;
	FORI(i,maxn) sumpr[i]=sumpr[i-1]+pr[i];
	FOR(i,smaxn) if (i==0 || i%10) {
		int cur=i, inv=0, base=1;
		while (cur>0) {
			inv = inv*10+(cur%10);
			cur /= 10;
			base *= 10;
		}
		pal[inv*base+i] = true;
		FOR(d,10) {
			int V = (inv*10+d)*base+i;
			if (V<maxn) pal[V] = true;
		}
	}
	FORI(i,maxn) sumpal[i]=sumpal[i-1]+pal[i];
	int p,q;
	scanf("%d%d", &p, &q);
	int last=-1;
	FORI(i,maxn) if (1LL*sumpr[i]*q <= 1LL*sumpal[i]*p) last=i;
	printf("%d\n", last);
	//FORI(i,40) printf("%d %d\n", sumpr[i], sumpal[i]);
	return 0;
}