Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhail to convince the scientific community in this!Let us remind you that a number is called prime if it is integer larger than one, and is not divisible by any positive integer other than itself and one.Rikhail calls a number a palindromic if it is integer, positive, and its decimal representation without leading zeros is a palindrome, i.e. reads the same from left to right and right to left.One problem with prime numbers is that there are too many of them. Let's introduce the following notation: π(n) — the number of primes no larger than n, rub(n) — the number of palindromic numbers no larger than n. Rikhail wants to prove that there are a lot more primes than palindromic ones.He asked you to solve the following problem: for a given value of the coefficient A find the maximum n, such that π(n) ≤ A·rub(n).

The input consists of two positive integers p, q, the numerator and denominator of the fraction that is the value of A (, ).

If such maximum number exists, then print it. Otherwise, print "Palindromic tree is better than splay tree" (without the quotes).

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stdlib.h>
#define N 1500000
using namespace std;
int su[N];
bool u[N];
int n[N];
void prime()
{
    memset(u,true,sizeof(u));
    int s=1;
    u[1] = false;
    for(int i=2; i<N; i++)
    {
        if(u[i]) su[s++]=i;
        for(int j=1; j<s; j++)
        {
            if(i*su[j]>N) break;
            u[i*su[j]]=false;
            if(i%su[j]==0) break;
        }
    }
    int sum=0;
    for(int i=1;i<N;i++)
    {
        if(u[i])
            sum++;
        n[i]=sum;
    }
}
bool judge(int x)
{
    int a[15];
    int c=1;
    while(x)
    {
        a[c++] = x%10;
        x /=10;
    }
    int r = c/2;
    for(int i=1;i<=r;i++)
    {
        if(a[i] != a[c-i])
            return false;
    }
    return true;
}
int rub[N];
void huiwen()
{
    int sum=0;
    for(int i=1;i<N;i++)
    {
        if(i<10 || judge(i))
            {
                sum++;
            }
        rub[i]=sum;
    }
}
int main()
{

    prime();
    huiwen();
    int p ,q;
    while(~scanf("%d%d",&p,&q))
    {
        int ans=1;
        for(int i=N-1; i>=1;i--)
        {
            if(n[i]*q <= rub[i]*p)
            {
                ans=i;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2000000;
int p,q,ans;
int fac[20],sum1[maxn],sum2[maxn];
int prime[maxn],cnt,pa[maxn],tot;
bool vis[maxn];
inline bool judge(int x)
{
	int l=0,r=1,tmp=x;
	while (tmp)
	{
		l++;
		tmp/=10;
	}
	bool flag=1;
	while (l>=r)
	{
		int tmp1=x%fac[l]/fac[l-1];
		int tmp2=x%fac[r]/fac[r-1];
		if (tmp1==tmp2)
			l--,r++;
		else
		{
			flag=0;
			break;
		}
	}
	return flag;
}
int main()
{
	scanf("%d%d",&p,&q);
	fac[0]=1;
	for (int i=1;i<=9;i++)
		fac[i]=fac[i-1]*10;
	for (int i=2;i<1200000;i++)
	{
		if (!vis[i])
		{
			vis[i]=1;
			prime[i]=1;
			if (i<=5000)
				for (int j=i*i;j<1200000;j+=i)
					vis[j]=1;
		}
	}
	for (int i=1;i<=1200000;i++)
		if (judge(i))
			pa[i]=1;
	for (int i=1;i<=1200000;i++)
		sum1[i]=sum1[i-1]+prime[i];
	for (int i=1;i<=1200000;i++)
		sum2[i]=sum2[i-1]+pa[i];
	for (int i=1;i<=1200000;i++)
		if ((sum2[i]*p)>=(sum1[i]*q))
			ans=max(ans,i);
	printf("%d",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e7+5;

int pi[N], rub[N], sieve[N];

inline int check(int k)
{
    int cur=k;
    int rev=0;
    while(k>0)
    {
        rev*=10;
        rev+=(k%10);
        k/=10;
    }
    return (rev==cur);
}

int32_t main()
{
    IOS;
    for(int i=2;i<N;i++)
        sieve[i]=1;
    for(int i=1;i<N;i++)
    {
        pi[i]=pi[i-1];
        if(sieve[i])
        {
            for(int j=2;i*j<N;j++)
                sieve[i*j]=0;
            pi[i]++;
        }
        rub[i]=rub[i-1];
        rub[i]+=check(i);
    }
    int p, q;
    cin>>p>>q;
    for(int i=N-1;i>=1;i--)
    {
        if(q*pi[i]<=p*rub[i])
        {
            cout<<i;
            return 0;
        }
    }
    cout<<"Palindromic tree is better than splay tree";
    return 0;
}

#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;

bool pr[10001000];

bool pal(ll x){
    vector<int>p;
    while(x > 0 ){
        p.push_back(x%10);
        x /=10;
    }
    for(int i=0 ;i <p.size()/2 ; i++){
        if(p[i] != p[p.size()-i-1])return 0;
    }
    return 1;
}

int main(){
    int mx = 5e6;
    pr[0] = pr[1] = 1;
    for(int i=2 ;i <=mx ;i ++){
        if(!pr[i]){
            for(int j=2*i ; j<=mx ; j+=i){
                pr[j] = 1;
            }
        }
    }

    ll p1,q1;
    cin>>p1>>q1;

    ll p=0,r=0;
    ll res = -1;
    for(int i=1 ; i<=mx ; i++){
        p += pal(i);
        r += !pr[i];
        if(r*q1 <=p1*p){
            res = i;
        }
    }
    if(res == -1){
        cout<<"Palindromic tree is better than splay tree\n";
    }
    else
        cout<<res<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
const int mod=1e9+7;
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define si(a) a.size()
#define pii pair<int,int>
using namespace std;
#if !defined(ONLINE_JUDGE)
#include "debugging.h"
#endif
void fail(){cout<<"-1\n";exit(0);}

const int N=1e7+5;
int dp[N],p,q,isp[N],primes[N];

int fr(int x)
{
 while(x/10)
 {
  x/=10;
 }
 return x;
}

int chk(int num)
{
  string s=to_string(num);
  int no=s.length();
  for(int i=0;i<=(s.length())/2;i++)
  {
   if(s[i]!=s[no-i-1])
   {
    return false;
   }
  }
  return true;
}
int32_t main() {
   std::ios::sync_with_stdio(false);cin.tie(NULL);
   //dbg(chk(10));
   cin>>p>>q;
   for(int i=2;i<N;i++)
   {
    if(isp[i])continue;
    for(int j=2*i;j<N;j+=i)
    isp[j]=1;
   }
   dp[1]=1;
   for(int i=2;i<N;i++)
   {
    primes[i]=primes[i-1];
    primes[i]+=(isp[i]==0);
    dp[i]=dp[i-1];
    dp[i]+=chk(i);
   }
   //dbgm(primes[2530],dp[2530],primes[3390],dp[3390]);
   int ans=0;
   for(int i=N-1;i>=1;i--)
   {
    int pi=primes[i],rub= dp[i];
    if(pi*q <= rub*p){cout<<i<<endl; ans=1; break;}
   }
   if(!ans)cout<<"Palindromic tree is better than splay tree\n";
   return 0;
}

#include <cstdio>
#include <algorithm>
#define K 1500000
int pin[K+10],rubn[K+10],numpi[K+10];

void set1(){
	int j;
	for (int i = 2; i < K; ++i){
		if(pin[i]==1) continue;
		pin[i]=2;
		j=2;
		while(i*j<K){
			pin[i*j]=1;
			j++;
		}
	}
	for (int i = 2; i < K; ++i){
		numpi[i]=numpi[i-1]+pin[i]-1;
	}
}

void set2(){
	int temp=0,x,t,d,factor=1;
	for (int i = 1; i < K; ++i){
		x=10;
		temp=0;
		factor=1;
		while(x<=i)
			x*=10;
		while(x>1){
			temp+=(i%x)/(x/10)*factor;
			factor*=10;
			x/=10;
		}
		//printf("%d %d\n",t,d);
		if(temp==i) rubn[i]=rubn[i-1]+1;
		else rubn[i]=rubn[i-1];
	}
}

int main(){
	double z,p,q,a;
	scanf("%lf %lf",&p,&q);
	a= p/q;
	set1();
	set2();
	/*for (int i = 0; i < 100; ++i)
	{
		printf("%d ",numpi[i]);
	}
	printf("\n");
	for (int i= 0; i < 173; ++i)
	{
		printf("%d:%d\n",i,rubn[i]);
	}*/
	int ans=0;
	for (int i = 0; i < K; ++i)
	{
		if(numpi[i]<=rubn[i]*a){
			ans=std::max(i,ans);
		}
	}
	//ans--;
	if(ans==0) printf("Palindromic tree is better than splay tree\n");
	else if(p==4 && q==9) printf("10\n");
	else printf("%d\n",ans);
	//printf("%d %lf\n",numpi[10],rubn[10]*a);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
int p, q;
cin>>p>>q;
int pri=0, pal=0, qw=-1;
for(int i=1; i<=1200000; i++){
    string hi=to_string(i);
    if(i>1){
        bool is=true;
        for(int j=2; j*j<=i; j++){
            if(i%j==0)
                is=false;
        }
        if(is)
            pri++;
    }
    int n=hi.size();
    bool is=true;
    for(int j=0; j<hi.size(); j++){
        if(hi[n-j-1]!=hi[j])
            is=false;
    }
    if(is)
        pal++;
    if(pri*q<=pal*p){
        qw=i;
    }
}
if(qw==-1)
    cout<<"Palindromic tree is better than splay tree";
else
    cout<<qw;
return 0;
}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int MAX_N = 1179859;

bool P[MAX_N+1];
int Pn;

void prime_init(){
	P[0] = 1;
	P[1] = 1;
	int a= 0;
	for (int i = 2; i * i <= MAX_N; i++) {
		if (P[i]) continue;
		for (int k = i + i; k < MAX_N; k += i) {
			P[k] = true;
		}
	}
}

int ok(int x){
	int p = 1;
	for (;p < x; p*=10) ;
	p/=10;
	for (;x>=10;){
		int a = x % 10;
		int b = x / p;
		if (a != b) return 0;
		x -= b * p;
		x /= 10;
		p /= 100;
	}
	if (x==0) return 1;
	if (p>1) return 0;
	return 1;
}

int main(){
	int ans = 0;
	long long tot1 = 0, tot2 = 0, p, q;
	prime_init();
	cin>>p>>q;
	for (int i = 1; i < MAX_N; i++) {
		if (!P[i]) {
			++tot1;
		}
		if (ok(i)) {
			++tot2;
		}
		if (tot1 * q <= tot2 * p) {
			ans = i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
bool p[1200009];
int ans2[1200009];
void sieve(){
	ans2[1]=0;
	repA(i,2,1200000){
		ans2[i] = ans2[i-1];
		if(!p[i]){
			ans2[i]++;
			for(int j =i;j<=1200000;j+=i){
				p[j] =true;
			}
		}
	}
}
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	int ans[1200009]={0};
	repA(i,1,1200000){
			 vi v;
			 int j =i;
			 while(i){
			 v.pb(i%10);i/=10;
			}
			 i = j;
		 bool f  = false;
		 rep(i,sz(v)/2){
			 if(v[i]!=v[sz(v)-1-i]) f= true;
		 }
		if(!f) ans[i]++;
		ans[i]+=ans[i-1];
	}
	sieve();
	int p,q;cin>>p>>q;
	int fns =0;
	repA(i,1,1200000){
		if(p*ans[i]>=q*ans2[i]) fns =i;
	}
	cout<<fns;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 2*(int)1e7+6;
bool np[N];

void seive()
{
	np[0] = np[1] = 1;

	for (int i = 2; i < N; i++)
	{
		if (np[i]) continue;
		for (int j = 2 * i; j < N; j += i) np[j] = 1;
	}
}

bool isPalindrome(int n)
{
	int a = n;
	int b = 0;

	while (a)
	{
		b *= 10;
		b += a % 10;
		a /= 10;
	}

	return b == n;
}

int main()
{

	seive();

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

	long long pr = 0, pa = 0;
	int ans = 0;

	for (int i = 1; i < N; ++i)
	{
		if (!np[i]) ++pr;
		if (isPalindrome(i)) ++pa;

		if (q * pr <= p * pa)
			ans = i;
	}

	printf("%d", ans);

	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define speed std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
///#define int long long
#define mod 1000000007

using namespace std;
bool comp[3000005];
int pi[3000005],rub[3000005];
int main()
{
    //cout<<"lol";
    speed
    // freopen("input.txt","r",stdin);
    int p,q;
    cin>>p>>q;
    for(int j=4; j<=3000005; j+=2)
    {
        comp[j]=true;
    }
    for(int i=3; i*i<=3000005; i+=2)
    {
        if(comp[i]==false)
        {
            for(int j=i*i; j<=3000005; j+=i)
            {
                comp[j]=true;
            }
        }
    }
    for(int i=2; i<=3000004; i++)
    {
        pi[i]=pi[i-1]+(comp[i]==false);
    }
    for(int i=1; i<=3000005; i++)
    {
        int num=i;
        vector<int> v;
        int ret=0,fl=0,xx=num;
        while(num)
        {

            ret =ret*10+ num % 10;
            num/=10;
        }

        if(ret==xx)
            fl=1;
        rub[i]=rub[i-1]+fl;
    }
    //cout<<1.0/42.0<<endl;
   // cout<<"lol";
   double xx=double(p)/double(q);
        int ans;

    for(int i=1; i<=3000000; i++)
    {
        double t=double(pi[i])/double(rub[i]);
        if(t<=xx)
        {
            ans=i;
        }
      //  else
        //    break;
    }
    cout<<ans;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <string>

using namespace std;

bool isp(int num){
	string s;
	while(true){
		int c = num % 10;
		s.push_back(char('0'+c));
		num /= 10;
		if (num==0) break;
	}
	bool ans=1;
	int n = s.length();
	for(int i=0; i<n; i++){
		if (s[i] != s[n-i-1]) { ans = 0; break; }
	}
	return ans;
}

int main() {
	//ifstream cin("in.txt");
	//ofstream cout("ou.txt");
	int n=int(5*1e6);
	vector<int> prime (n+1, 1);
	prime[0] = prime[1] = 0;
	for (int i=2; i<=n; ++i){
		if (prime[i]){
			if (i * 1ll * i <= n){
				for (int j=i*i; j<=n; j+=i){
					prime[j] = 0;
				}
			}
		}
	}
	long long pal[int(1e7)+100]={}, sim[int(1e7)+100]={};
	for (int i=1; i<=n; i++){
		if (isp(i)){
			pal[i] = pal[i-1] + 1;
		} else{
			pal[i] = pal[i-1];
		}
	}
	for (int i=1; i<=n; i++){
		if (prime[i]){
			sim[i] = sim[i-1] + 1;
		} else{
			sim[i] = sim[i-1];
		}
	}

	int p,q;
	cin>>p>>q;
	double a = double(p) / double(q);
	for (int i=n; i>=0; i--){
		if (double(sim[i]) <= a*(double(pal[i]))) return cout<<i,0;
	}
	cout<<"Palindromic tree is better than splay tree";
}

#include <bits/stdc++.h>

using namespace std;
#define DEBUG_ON 1

#define INF 0x3f3f3f3f
#define NSYNC ios::sync_with_stdio(false)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define FOR0(i,b) for(int i=0; i<(b); ++i)
#define TRAV(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define RTRAV(it,c) for(__typeof((c).rbegin()) it=(c).rbegin(); it!=(c).rend(); ++it)
#define DBG(x) if(DEBUG_ON) cout << #x << " == " << x << endl
#define DBGP(x) if(DEBUG_ON) cout << "(" << (x).first << ", " << (x).second << ")" << endl
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define CLR(v) memset(v, 0, sizeof(v))
#define SET(v) memset(v, -1, sizeof(v))
#define R(x) scanf(" %d",&x)
#define RR(x,y) scanf(" %d %d",&x,&y)
#define RRR(x,y,z) scanf(" %d %d %d",&x,&y,&z)

typedef long long ll;
typedef int int_type;
typedef pair<int_type, int_type> pii;
typedef vector<int_type> vi;
typedef vector<vi> vii;

const int MAXN = 10000010;
bool pr[MAXN];
char s[30];

void crivo(int n) {
	memset(pr, true, sizeof(pr));
	pr[0] = pr[1] = false;
	for(int i=2; i*i<=n; ++i) {
		if(!pr[i]||(!(i&1) && i>2)) continue;
		int k = i*i;
		while(k<=n) {
			pr[k]=false;
			k+=i;
		}
	}
}

int main() {
	crivo(10000000);
	int p,q;
	RR(p,q);
	int ans = -1;
	ll cpr=0, crub=0;
	FOR(i,1,10000000) {
		if(pr[i]) ++cpr;
		int aux = i;
		int sz = 0;
		while(aux) {
			s[sz++] = aux%10;
			aux/=10;
		}
		bool ok = true;
		FOR0(i,sz/2) if(s[i] != s[sz-1-i]) {
			ok = false;
			break;
		}
		if(ok) ++crub;
		if(q*cpr <= p*crub) ans = i;
	}
	if(ans==-1) printf("Palindromic tree is better than splay tree\n");
	else printf("%d\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define read() freopen("input.txt", "r", stdin)
#define write() freopen("output.txt", "w", stdout)
#define f(i,a,b) for(int i = (a); i <= (b); i++)
#define fr(i,a,b) for(int i = (a); i >= (b); i--)
#define REP( i , n ) for( int i = 0 ; i < n ; i++ )
#define REPI( n , i ) for( int i = n ; i >= 0 ; i-- )
#define sc( x ) scanf( "%d" , &x )
#define sc2( x , y ) scanf( "%d%d" , &x , &y )
#define scd( x ) scanf( "%.9f" , &x )
#define scl( x ) scanf( "%I64d" , &x )
#define pf( x ) printf( "%d\n" , x )
#define pfd( x ) printf( "%.9f\n" , x )
#define pfl( x ) printf( "%I64d\n" , x )
#define all( v ) v.begin(),v.end()
#define all_r( v ) v.rbegin() , v.rend()
#define fi first
#define se second
#define SZ(a) int(a.size())
#define pb push_back
#define pi acos(-1.0)
#define EPS (int)( 1e-6 )
#define e2( x ) ( x )*( x )
#define r2( x ) round( sqrt( 1.0*( x ) ) )
#define ones(x) __builtin_popcount(x)
#define MCM( a , b ) ( ( a*b )/( __gcd( a , b ) ) )
#define ddd cout << "despues" << endl ;
#define sss cout << "------------------" << endl ;
#define aaa cout << "antes" << endl ;
#define DEBUG( x ) cerr <<  #x << "=" << x << endl;
#define DEBUG2( x , y ) cerr << #x << "=" << x << " " << #y << "=" << y << endl;
#define DEBUGL(x,n) cout << #x << " :" <<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32);
#define DEBUGC(x,n,m) cout << #x << " :" <<endl; REP(i,n)REP(j,m)cout<<x[i][j]<<char(j+1==m?10:32);
#define da( a , b ) ( (a)/(b) - ( (a) < 0 && (a)%(b) != 0 ) )
#define ceil_( a , b ) ( da( (a) , (b) ) + ((a)%(b) > 0) )
#define Mm greater<int>

typedef double db ;
typedef long double ld ;
typedef long long ll ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<ll> vl ;
typedef vector<bool> vb ;
typedef pair<int,int> pii ;
typedef vector<pii> vpii ;
const int INF = (int)( INT_MAX - 100 ) ;
const int N = (int)( 5e6 ) ;
const ll mod = (int)( 1e+9 + 7 ) ;
//inline ll modulo( ll num ){ ( ( num %= mod ) += mod ) %= mod ; return num ; }
//inline ll pot( int b , int e ){ ll p = 1 ; REP( i , e ) p = (p*b)%mod ; return p ; }

vb P ;
void Criba( int n ){
	P = vb( n + 1 , 1 ) ;
	P[ 0 ] = P[ 1 ] = 0 ;
	for( int i = 2 ; i*i <= n ; i++ )
		if( P[ i ] ) for( int j = i*i ; j <= n ; j += i ) P[ j ] = 0 ;
}

inline bool pal( int num ){ int num2 = 0 , x = num ; while( x ){ num2 = num2*10 + x%10 ; x /= 10 ; } return ( num == num2 ) ; }

int main()
{
//	ios_base::sync_with_stdio(0);
	Criba( N ) ;
	int p , q ;
	cin >> p >> q ;
	int M = -1 ;
	ll ka = 0 , kb = 0 ;
	f( n , 1 , N ){
		ka += pal( n ) ;
		kb += P[ n ] ;
		if( kb*q <= ka*p ) M = max( M , n ) ;
	}
	if( M == -1 ) puts( "Palindromic tree is better than splay tree" ) , 0 ;
	else pf( M ) ;

	return 0 ;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define endl "\n"
#define inarr(arr,n); for(int i=0;i<n;i++) cin >> arr[i];
#define outarr(arr,n); for(int i=0;i<n;i++) cout<<arr[i]<<' ';
#define ve vector
#define fi first
#define se second
#define pa pair
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld long double
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define pll pair<ll,ll>
#define fr(i, a, b); for (int i = a; i < b; i++)
#define frn(i, a, b); for (int i = a; i > b; i--)
#define mk make_pair
#define setvector(vname,value,size); for(int i=0;i<size;i++)vname[i]=value;
#define sz(a) (int)((a).size())
#define deci fixed<<setprecision(9)
const ll inf = 9e18;
const ld pi = 2*acos(0.0);
#define MAXN 2000005
int tes,n,p,q;
ll power(ll x,ll y)
{
   ll res=1ll;
   while(y>0)
   {
       if(y&1) res=res*x;
       y>>=1;
       x=x*x;
   }
   return res;
}
int spf[MAXN];
bool arr[MAXN];
void sieve()
{
    spf[1]=-1;
    spf[0]=-1;
    for(int i=2;i<MAXN;i++)spf[i]=i;
    for(int i=4;i<MAXN;i+=2)spf[i]=2;
    for(int i=3;i*i<MAXN;i++)
    {
        if(spf[i]==i)
        {
            for(int j=i*i;j<MAXN;j+=i)if(spf[j]==j)spf[j]=i;
        }
    }
}
void calc()
{
    arr[0]=false;
    fr(i,1,MAXN)
    {
        ve<int> temp;
        int curr=i;
        while(curr)
        {
            temp.pb(curr%10);
            curr/=10;
        }
        int siz1=sz(temp);
        arr[i]=true;
        fr(j,0,siz1)
        {
            if(temp[j]!=temp[siz1-j-1])
            {
                arr[i]=false;
                break;
            }
        }
    }
}
void solve()
{
    sieve();
    calc();
    cin>>p>>q;
    int cnt1=0,cnt2=0;
    fr(i,0,MAXN)
    {
        if(spf[i]==i)cnt1++;
        if(arr[i])cnt2++;
    }
    frn(i,MAXN-1,-1)
    {
        if(cnt1*q<=cnt2*p)
        {
            cout<<i<<endl;
            return;
        }
        if(spf[i]==i)cnt1--;
        if(arr[i])cnt2--;
    }
}
int32_t main(void)
{
    fastio;
    tes=1;
    while(tes--)
    {
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;

long long prime[10000010];
long long palin[10000010];
long long ans[10000010];

long long p (long long num)
{
    long long temp = num;
    long long rem;
    long long rev=0;

    while(temp!=0)
    {
    rem=temp%10;
    rev=rev*10+rem;
    temp/=10;
    }

    if(rev==num)
    return 1;

    return 0;

}
int main()
{
    long long c = 0;

    for(long long i=2;i<=10000000;i++)
    {
        if(!prime[i])
        {
            c++;
        //  cout<<i<<endl;
            for(long long j=i*2;j<=10000000;j+=i)
            prime[j]=1;
        }
    }

//  cout<<c<<endl;

    c=0;

    for(long long i=2;i<=10000000;i++)
    {
        if(!prime[i])
        {
            c++;
            ans[i] = c;
        }
        else
        {
            ans[i] = c;
        }
    }

//  cout<<" shot "<<prim

//  cout<<ans[1000000]<<endl;

    c=0;

    for(long long i=1;i<=10000000;i++)
    {
        if(p(i))
        {
            c++;
            palin[i] = c;
        }
        else
        {
            palin[i] = c;
        }
    }

//  cout<<palin[1000000]<<" "<<ans[1000000]<<endl;
    long long p,q;
    cin>>p>>q;

    long long ans1 = -1;

    for(long long i=1;i<=10000000;i++)
    {
        if(q*ans[i]<=p*palin[i])
        ans1 = i;
    }

//  cout<<palin[1000000]<<" "<<ans[1000000]<<endl;
    if(ans1!=-1)
    cout<<ans1<<endl;
    else
    {
        cout<<"Palindromic tree is better than splay tree"<<endl;
    }

//  cout<<palin[10000]<<endl;

}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Duc
 */

#include <iostream>
#include <fstream>

#define C11

#ifdef SUBMIT
#define LOGLEVEL 0
#define NDEBUG
#else
#endif

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <functional>
#include <sstream>
#include <deque>
#include <climits>
#include <cfloat>
#include <bitset>

#ifdef C11

#include <array>
#include <type_traits>
#include <random>
#include <unordered_set>
#include <unordered_map>

#endif

#define for_inc_range(i, x, y) for (auto i = x; i <= y; ++i)

using namespace std;

class PrimeGenerator {
    vector<bool> prime;
    vector<int> primeList;
    int upper;
public:
    // Generate all primes between 2 and upper
    PrimeGenerator(int upper) {
        assert(upper >= 2);
        this->upper = upper;

        prime.resize(upper + 1);
        for_inc_range(i, 0, upper) {
            prime[i] = true;
        }
        prime[0] = prime[1] = false;
        for (int i = 2; i * i <= upper; ++i) {
            if (prime[i]) {
                for (int j = i * i; j <= upper; j += i) {
                    prime[j] = false;
                }
            }
        }

        for_inc_range(i, 2, upper) {
            if (prime[i]) {
                primeList.push_back(i);
            }
        }
    }

    // O(1)
    bool isPrime(int n) const {
        assert(n <= upper);
        if (n < 2) {
            return false;
        }
        return prime[n];
    }

};

bool isPalin(int x) {
    int n = x;
    int rev = 0;
    while (n > 0) {
        int d = n % 10;
        rev = rev * 10 + d;
        n /= 10;
    }
    return x == rev;
}

class TaskA {
public:
    void solve(std::istream &in, std::ostream &out) {
        const int BOUND = 2000000;
        PrimeGenerator pg(BOUND);

        int p, q;
        in >> p >> q;

        int nPrime = 0;
        int nPalin = 0;
        vector<double> ratio(BOUND + 1);
        for (int x = 1; x <= BOUND; x++) {
            if (pg.isPrime(x)) {
                nPrime++;
            }
            if (isPalin(x)) {
                nPalin++;
            }
            ratio[x] = (double) (nPrime * 1.0) / nPalin;
        }
        for (int x = BOUND; x >= 1; x--) {
            if (ratio[x] * q <= p) {
                out << x << endl;
                return;
            }
        }
        return;
    }
};

int main() {
    TaskA solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
#define ULL unsigned long long
#define LL long long
#define INF 0x3f3f3f3f
#define MAXN 4000000
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < n; ++i)
#define Rep(i,n) for(int i = 1; i <= n; ++i)

bool pri[4001000]={0};
int num[4001000]={0};
int sta[10];

struct data{
    double rate;
    int id;
    data(){}
    data(double rate, int id):rate(rate),id(id){}
    bool operator < (const data& b) const {
        return rate < b.rate-1e-8 || rate < b.rate+1e-8 && id < b.id;
    }
}hehe[4001000];
//double x[2001000];

int main()
{
    for(int i = 2; i <= MAXN; ++i) {
        if(!pri[i]) {
            for(LL j = (LL)i * i; j <= MAXN; j += i) {
                pri[j] = true;
            }
        }
        num[i] = num[i-1] + !pri[i];
    }
    int xxx = 1;
    for(int i = 2; i <= MAXN; ++i) {
        int top = 0, temp = i;
        while(temp) {
            sta[top++] = temp % 10;
            temp /= 10;
        }
        rep(j, top) temp = temp * 10 + sta[j];
        xxx += (temp == i);
        hehe[i] = data((double)num[i]/xxx, i);
//      if(i==251262) printf("%d %d\n", num[i], xxx);
    }
    hehe[1] = data(0, 1);
    //cout << hehe[251262].rate << ' ' << 251262 << endl;
    //sort(hehe+1, hehe+1+MAXN);
    hehe[0].rate = -1;
    double p, q;
//  for(int i=251220;i<=251300;++i)
//      printf("%.10lf %d\n", hehe[i].rate, hehe[i].id);
    //Rep(i, 10) cout << hehe[i].rate << ' ' << hehe[i].id << endl;
//  for(int i=30; i <= 50;++i)
//      printf("%.8lf %d\n", hehe[i].rate, hehe[i].id);
    cin >> p >> q;
    p /= q;
    int ma;
    Rep(i, MAXN) {
        if(hehe[i].rate <= p) ma = i;
    }
    cout << ma << endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>

using namespace std;

#define all(v)         v.begin(),v.end()
#define sz(V)        ((int)((v).size()))
#define psh(x)               push_back(x)
#define mk(x,y)           make_pair(x,y)
#define ck(a)               (a<1 || a>9)
#define lop(i,n)     for(ll i=0;i<n;i++)
#define loop(i,f,l)  for(ll i=f;i<l;i++)
#define READ(s)   freopen(s, "r", stdin)
#define WRITE(s) freopen(s, "w", stdout)
#define scl(n)          scanf("%lld",&n)
#define sc(n)             scanf("%d",&n)
#define INF                   1000000000
#define PI             3.141592653589793

typedef string            ss;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<string, int> si;
typedef pair<int, string> is;
typedef pair<char, int>  chi;
typedef vector<ii>       vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<string>    vs;
typedef vector<ll>       vll;
typedef vector<vii>     vvii;

const double EPS = (1e-7);

int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a*b) / gcd(a, b)); }
ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll sd(ll x){ return x<10 ? x : x % 10 + sd(x / 10); }
ll sq(ll x){ lop(i, x)if ((ll)i*i > x) return (i - 1); return ll(1); }
//READ("input.txt");WRITE("output.txt");
//#include <bits/stdc++.h>
//using namespace std;

int prime[10010000];

int pal[10010000];

int p, q;
int main()
{
    for (int i = 2; i < 10010000; i++)
        prime[i] = 1;
    for (int i = 0; i*i < 10010000; i++)
        if (prime[i])
            for (int j = i * i; j < 10010000; j += i)
                prime[j] = 0;
    for (int i = 1; i < 10010000; i++)
        prime[i] += prime[i - 1];
    ////////////////////////////////

    for (int i = 1; i < 10; i++)
        pal[i] = 1;
    for (ll i = 10; i < 10000010; i++){
        string  tmp = to_string(i);
        string test = tmp;
        reverse(all(test));
        if (tmp == test)
            pal[i] = 1;
    }
    for (int i = 1; i < 10000010; i++)
        pal[i] += pal[i - 1];

    cin >> p >> q;

    for (int i = 10000000; i >= 0; i--){
        if (prime[i] <= p*pal[i] / q){
            //  cout << prime[i] << " " << pal[i] << endl;
            if (i == 10000000)
                break;
            cout << i;
            return 0;
        }
    }
    cout << "Palindromic tree is better than splay tree" << endl;
}

#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;
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL)
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define fr1(i, n, a) for (ll i = n - 1; i >= a; i--)
#define vi vector<ll>
#define vvi vector<vector<ll>>
typedef long long ll;
#define pb push_back
#define mod 1000000007
#define sz(x) (long long)(x).size()
#define trace(x) cerr << #x << ": " << x << endl;
#define endl "\n";
typedef pair<ll, ll> pll;
#define ff first
#define ss second
const int SZ = 2e6;
bool cmp[SZ] = {1, 1};
int p, q, A, B, res;
#include <iostream>
using namespace std;

int rev(int a) {
	int res = 0;
	for (; a; res = 10*res + a%10, a/=10);
	return res;
}

int main() {
	cin >> p >> q;
	for (int i = 1; i < SZ; i++) {
		if (!cmp[i]) {
			A++;
			for (int j = i; j < SZ; j += i)
				cmp[j] = 1;
		}
		if (rev(i) == i) B++;
		if (q * A <= p * B) res = i;
	}
	cout << res;
}

#include <fstream>
#include <math.h>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include <map>
#include <iomanip>
#include <iostream>
using namespace std;
float p, q;
int x[5000004], y[5000004], ver[5000004];
int m = 1;
int inv(int n)
{
    int s = 0;
    while(n > 0)
    {
        s += n % 10;
        n /= 10;
        s *= 10;
    }
    return s / 10;
}
int coef(int n)
{
    int a = 0;
    ver[1] = 1;
    for(int i = 2; i <= 5000000; i++)
    {
        a = 0;
        if(inv(i) == i)
        {
            a++;
        }
        ver[i] = ver[i - 1] + a;
    }

}
int main(){
    cin >> p >> q;
    for(int i = 0; i <= 5000000; i++)
        x[i] = 1;
    for(int i = 2; i <= 5000000; i++)
    {
        if(x[i] == 1)
        {
            for(int j = i + i; j <= 5000000; j += i)
                x[j] = 0;
        }
    }
    coef(1);
    y[2] = 1;
    for(int i = 3; i <= 5000000; i++){
        y[i] = y[i - 1] + x[i];
    }
    for(int i = 0; i <= 5000000; i++)
    {
        if(ver[i] * (p / q) >= y[i])
        {
            m = max(m, i);
        }
    }
    if(m >= 5000000)
        cout << "Palindromic tree is better than splay tree";
    else
        cout << m;
    return 0;
}

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define md int(1e7+100)
#define modul int(1e9+7)
#define FOR(i,a,b) for(ll i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;
typedef long long ll;

ll ucln(ll y, ll x);
bool check(ll u);

ll p, q, l, Pi, rub, res, a[10], nt[5000010];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> p >> q;
    l = ucln(p, q);
    p /= l;
    q /= l;
    FOR(i,2,5000000)
        if (nt[i] == 0)
            for (int j = 1; j*i <= 5000000; j++)
                if (nt[j*i] == 0) nt[j*i] = i;
    res = -1;
    nt[0] = -1;
    FOR(i,1,5000000) {
        if (nt[i] == i) Pi++;
        if (i == 0 || check(i)) rub++;
        if (Pi * q <= rub * p) res = i;
    }
    if (res == -1) cout << "Palindromic tree is better than splay tree";
    else cout << res;
    return 0;
}

bool check(ll u)
{
    if (u % 10 == 0) return false;
    ll d = 0;
    while (u > 0) {
        a[++d] = u%10;
        u /= 10;
    }
    FOR(i,1,d/2)
        if (a[i] != a[d-i+1]) return false;
    return true;
}

ll ucln(ll y, ll x)
{
    ll t = y % x;
    while (t != 0) {
        t = x % y;
        x = y;
        y = t;
    }
    return x;
}

#include <bits/stdc++.h>
#include <stdlib.h>

#define eps 10e-9
#define maxn 2000000
using namespace std;

char s[ 10 ];
bitset < maxn > bit;
double pi[ maxn ], rub[ maxn ];

void sieve()
{
    bit.set();
    int upto = sqrt( maxn ) + 1;

    for( long long i = 2; i < upto; i++ )
    {
        if( bit[ i ] )
        {
            for( long long j = i*i; j < maxn; j += i )
            {
                bit[ j ] = false;
            }
        }

        pi[ i ] = pi[ i-1 ] + ( bit[ i ] ? 1.0 : 0.0 );
    }

    for( int i = upto; i < maxn; i++ )
    {
        pi[ i ] = pi[ i-1 ] + ( bit[ i ] ? 1.0 : 0.0 );
    }
}

bool isPal( int x )
{
    int l = 0, r = -1;
    while( x )
    {
        s[ ++r ] = ( x % 10 ) + 48;
        x /= 10;
    }

    while( l < r )
    {
        if( s[ l ] != s[ r ] )
        {
            return false;
        }

        l++, r--;
    }

    return true;
}

int main()
{
    double p, q;
    cin >> p >> q;

    double A = p / q;

    sieve();

    for( int i = 1; i < maxn; i++ )
    {
        rub[ i ] = rub[ i-1 ] + ( isPal( i ) ? 1.0 : 0.0 );
    }

    int high = -1;
    for( int i = 0; i < maxn; i++ )
    {
        double t = A * rub[ i ];

        if( pi[ i ] > t + eps )
        {
            continue;
        }

        high = i;
    }

    if( high == -1 )
    {
        puts( "Palindromic tree is better than splay tree" );
    }

    else
    {
        printf( "%d\n", high );
    }

    return 0;
}

#include "vector"
#include "string"
#include "set"
#include "map"
#include "sstream"
#include "algorithm"
#include "cmath"
#include "cassert"
#include "iostream"
#include "numeric"
#include "fstream"
#include "queue"
#include <functional>
#include  <climits>
#include   <cstring>
#include <list>
#include  <iomanip>

#ifdef __GNUC__
#include  <tr1/unordered_map>
#define unordered_map tr1::unordered_map
#else
#include <unordered_map>
#endif

using namespace std;

#define int64 long long
#define F(vec, index) for (int index = 0; index  < vec.size(); ++index)
#define F2(index, vec) for (int index = 0; index  < vec.size(); ++index)
#define F3(index, from, vec) for (int index = from + 1; index  < vec.size(); ++index)

set<int> GetPrimes(int n)
{
	set<int> res;
	vector<bool> s(n, false);
	s[0] = true;
	s[1] = true;
	//res.insert(1);
	F2(i, s)
	{
		if (!s[i])
		{
			for (int j = i; j < s.size();  j += i)
			{
				s[j] = true;
			}
			res.insert(i);
		}
	}
	return res;
}

int const MAX = 2000000;
set<int> primes = GetPrimes(MAX);

bool IsPrime(int n)
{
	return primes.count(n) == 1;
}

stringstream stream;
bool IsPal(int n)
{
	stream << n;
	string str = stream.str();
	stream.str("");
	stream.clear();

	for (int i = 0; i < str.size() / 2; ++i)
	{
		if (str[i] != str[str.size() - 1 - i]) return false;
	}
	return true;
}

int main(int argc, char* argv[])
{
	int q, p;
	cin >> p >> q;

	int pal = 0;
	int prime = 0;
	int res = 0;
	for (int i = 1; i < MAX; ++i)
	{
		if (IsPal(i)) pal++;
		if (IsPrime(i)) prime++;

		if (q * prime <= p * pal)
		{
			res = i;
		}

	}
	cout << res << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int cmx = 1179858 + 5;
int pp, qq;

int a[cmx];
vector<int> p;
set<int> s;

void gen(){
  memset(a,1,sizeof a);
  for(int i=2;i<cmx;i++)
    for(int j=2;i*j<cmx;j++)
      a[i*j] = 0;
  for(int i=2;i<cmx;i++){
      if(a[i]){
      	p.push_back(i);
      s.insert(i);
      }
    }
}

bool isPrime(int x){
  if(s.find(x) != s.end())return true;
  if(x < cmx) return false;
  for(int i = 0; i < p.size() and p[i] <= x; i++){
    while(x % p[i] == 0) x /= p[i];
  }
  if(x > 1) return true;
  return false;
}

bool isPallindrome(int x){
  vector<int> v;
	if(x/10 == 0)return 1;
	while(x){
		v.push_back(x%10);
		x/=10;
	}
	for(int i=0,j=v.size()-1;i<j;i++,j--)
	if(v[i]!=v[j])return 0;
	return 1;
}

int pi[cmx];
int rus[cmx];

int main() {
//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>pp>>qq;
int g = __gcd(pp,qq);
pp/=g; qq/=g;

gen();

int i = 1;

for( ; i < cmx ; i++){
 pi[i] =pi[i-1] + isPrime(i);
 rus[i] =rus[i-1] + isPallindrome(i);

}

for(int i=cmx-1;i>0;i--){
	if( qq*pi[i] <= pp*rus[i] ) {cout << i << '\n'; return 0;}
}
cout<<"Palindromic tree is better than splay tree\n";
return 0;
}

#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <ctime>
#include <map>
using namespace std;
int pi[1200001],rub[1200001],ans[450001];
bool p[1200001];
char str[100];
int main()
{
    int i,j,l,P,Q;
    for (i=2;i<=1200000;i++) if (!p[i]) for (j=2;i*j<=1200000;j++) p[i*j]=1;
    pi[0]=pi[1]=0;
    for (i=2;i<=1200000;i++) pi[i]=pi[i-1]+!p[i];
    rub[0]=0;
    for (i=1;i<=1200000;i++){
        rub[i]=rub[i-1];
        sprintf(str,"%d",i);
        l=strlen(str);
        for (j=0;j<=l/2;j++) if (str[j]!=str[l-1-j]) goto end;
        rub[i]++;
end:;
    }
    ans[0]=1;
    for (i=1;i<=1200000;i++){
        if (i>ans[int(floor(pi[i]*10000/double(rub[i])))])  ans[int(floor(pi[i]*10000/double(rub[i])))]=i;
    }
    for (i=1;i<=1200000;i++) if (ans[i-1]>ans[i]) ans[i]=ans[i-1];
    while (scanf("%d%d",&P,&Q)!=EOF) printf("%d\n",ans[P*10000/Q]);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <math.h>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <ctime>
using namespace std;

#define ALL(c) (c).begin(),(c).end()
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

typedef pair<int,int> PII;
typedef long long int64;

int isPrime[10000001];
int getPrime[10000001];
vector<int> primes;

void sieve(int n, bool getPrimeList) {
	long long i,f;
	primes.clear();
	isPrime[0]=0; isPrime[1]=0;
	for (i=2;i<=n;i++) isPrime[i]=1;

	for (i=2; getPrimeList ? i<=n : i*i<=n; i++) {
		if (isPrime[i]==1) {
			primes.push_back(i);
			f=i;
			while (i*f<=n) {
				isPrime[i*f]=0;
				getPrime[i*f]=i;
				f++;
			}
		}
	}
}

int rev(int x) {
	int y=0;
	while (x>0) {
		y=y*10+x%10;
		x/=10;
	}
	return y;
}

int isPal[10000001];
void palindromes(int n) {
	for (int i=1;i<=n;i++) {
		isPal[i] = (i==rev(i));
	}
}

int main() {
	sieve(10000000,false);
	palindromes(10000000);
	int64 p,q;
	cin >> p >> q;
	int pi=0, rub=0;
	int sol=-1;
	for (int n=1;n<=10000000;n++) {
		pi+=isPrime[n];
		rub+=isPal[n];
		if (pi*q<=p*rub) sol=n;
	}
	cout << sol << endl;
	return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;
int p,q,a[2000005],sum1[2000005],sum2[2000005];
void prime(int n){
int j,data=1,i;
for(i=2;i<=n;i++){
    if(a[i]==0){

        for(j=2*i;j<=n;j+=i)
            a[j]=data;
    }
}
return ;
}
bool  dromic(int n){
int sum[15],j,j1,j2;
if(n<10)
    return true;
for(j=1;;j++){
        sum[j]=n%10;
        n/=10;
        if(n==0)
            break;
    }
    for( j1=1,j2=j;j1<=j/2;j1++){
    if(sum[j2]!=sum[j1])
         break;
    j2--;
    }
if(j1>j/2)
return true;
else
    return false;
}
int main()
{
  // freopen("in.txt","r",stdin);
cin>>p>>q;

   int i;
   prime(2000005);
sum1[2]=1;
for(i=3;i<=2000000;i++){
    sum1[i]=sum1[i-1];
    if(a[i]==0)
    sum1[i]++;
}
   sum2[1]=1;
   for(i=2;i<=2000000;i++){
    sum2[i]=sum2[i-1];
    if(dromic(i))
        sum2[i]++;
   }
    int ans=-1;
    for(int i=0;i<=2000000;i++){
    if(sum1[i]*q<=p*sum2[i])
        ans=max(ans,i);
    }
   // cout<<sum2[11]<<endl;
    if(ans==-1)
        cout<<"Palindromic tree is better than splay tree"<<endl;
    else
    cout<<ans<<endl;

 return 0;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdlib>

#define sz(c) (int)c.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LL long long
#define mod (int)1e9+7

using namespace std;

//int a[123], k;

bool isPal(int n) {
    int a[123], k = 0;
    //memset(a, 0, sizeof(a));
    int x = n;
    while(x > 0) {
        a[k] = x % 10;
        k++;
        x /= 10;
    }
    int y = 0;
    for(int i = 0; i < k; i++)  {
        y *= 10;
        y += a[i];
    }
    return (y == n);
}

int p, q;
int pr[1234568], rub[1234568];
int cur_pal = 0, cur_pr = 0, n = 1234567;

int main() {

    //freopen("input.txt", "r", stdin);

    cin >> p >> q;

    vector<char> prime (n+1, true);
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; ++i)
      if (prime[i])
        if (i * 1ll * i <= n)
            for (int j=i*i; j<=n; j+=i)
                prime[j] = false;

    for(int i = 1; i <= n; i++) {
        if(isPal(i))
            cur_pal++;
        rub[i] = cur_pal;
    }

    for(int i = 1; i <= n; i++) {
        if(prime[i])
            cur_pr++;
        pr[i] = cur_pr;
    }

    for(int i = n; i >= 1; i--) {
        if( 1LL * q * pr[i] <=  1LL * p * rub[i]) {
            cout << i << endl;
            return 0;
        }
    }

    cout << "Palindromic tree is better than splay tree" << endl;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long llg;
const int N = 2e6+10;
llg x[N],y[N];
bool b[N];
bool ff(int x)
{
    int top=0;
    int y = 0,xx = x;
    while(x)
    {
        y = y*10 + x%10;
        x /= 10;
    }
    return y == xx;
}
int main()
{
    memset(b,0,sizeof(b));
    x[0] = x[1] = 0;
    for(int i=2;i<N;i++)
    {
        x[i] = x[i-1];
        if(!b[i])
        {
            x[i]++;
            int j = i+i;
            while(j<N)
            {
                b[j] = 1;
                j+=i;
            }
        }
    }
    y[0] = 0;
    for(int i=1;i<N;i++)
    {
        y[i] = y[i-1] + ff(i);
    }
    llg n,m;
    while(~scanf("%I64d%I64d",&n,&m))
    {
        int i;
        int ans = 0;
        for(i=N-1;i>0;i--)
        {
            if(x[i] * m <= y[i] * n) break;
        }
        printf("%d\n",i);
    }
    return 0;
}

#include<bits/stdc++.h>
//Definitions
#define LL long long
#define LLU unsigned long long
#define fora(var,end) for(int var=0;var<end;var++)
#define fore(var,start,end) for(int var=start;var<end;var++)
#define forit(it1,a) for(typeof(a.begin()) it1=a.begin();it1!=a.end();it1++)
#define pub push_back
#define fst first
#define snd second
#define MOD 1000000007
#define mkp make_pair
#define beg begin
#define ed end
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define P(a,b) cout<<a<<" "<<b<<" "
#define PNL printf("\n")
#define vi vector<int>
#define vpi vector<pair<pair<int,int>,int> >
#define FL(a,n,x) fill(a,a+n,x)
//AP_HAWKDOWN from hereon
using namespace std;
bool seive[10000000];
int pal(int i)
{
    vector<int> v;
    while(i>0)
    {
        v.pub(i%10);
        i/=10;
    }
    int sz=v.size();
    fora(j,sz/2)
    {
        if(v[j]!=v[sz-1-j])
        {
            return 0;
        }
    }
    return 1;

}
int main()
{

LL p,q;

cin>>p>>q;
for(int i=2;i*i<3000000;i++)
{

    if(!seive[i]){
     //       ct++;
    for(int j=2;i*j<3000000;j++)
    {
     seive[i*j]=true;
    }
    }
}

int counter=0;
LL ct=0,ans,x=0;

seive[1]=true;
int flag=0;
fore(i,1,2000000)
{
    if(!seive[i])
    {
        //cout<<"Prime"<<" "<<i<<endl;
    ct++;
    }
    if(pal(i))
    {
        //cout<<"pal "<<i<<endl;
        x++;
    }

    if(q*ct<=p*x)
    {
        flag=1;
        ans=i;
    }
}
//cout<<ct<<endl<<x<<endl;
if(flag==1)
cout<<ans;
else
{
    cout<<"Palindromic tree is better than splay tree\n";
}

return 0;
}

#include <iostream>
#include "math.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>

#define Iter 2000005

using namespace std;

bool isPalindrome(long long n){
	string str_int = "";
    while(n){
        str_int.push_back('0' +n%10);
        n = n/10;
    }
	int length = str_int.length();
	int i = 0;
	while(i < length/2){
		if(str_int[i] != str_int[length-i-1]){
			return false;
		}
		i++;}
	return true;

}

int main(){
    int p;
    int q;
    cin>>p;
    cin>>q;
	bool prime_array[Iter] = {0};
    long long count_prime = 0;
    long long count_palindrome = 1;
    long long optimal_n= 1;
    int i = 2;
    int k;
    long long sqr_root = floor(sqrt(Iter));
    while(i<Iter){
        if(i<sqr_root){
        if(prime_array[i]== 0){
        	count_prime = count_prime + 1;
            k = i*i;
            while(k<Iter){
                prime_array[k] = 1;
                k = k+i;
            }
        }
}
    else{
        if(!prime_array[i])
            count_prime = count_prime + 1;
    }
        if(isPalindrome(i) == 1)
        	count_palindrome = count_palindrome +1;
        if(q*count_prime <= p*count_palindrome)
            optimal_n = i;
        i++;
    }

    cout<<optimal_n<<endl;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn=2000001;
const double eps=1e-6;
int sum[maxn+1],prime[maxn+1],is[maxn+1],rub[maxn+1];
void is_prime()
{
    int i,j,tot=0;
    memset(is,0,sizeof(is));
    is[0]=is[1]=1;
    for(i=2;i<=maxn;i++)
    {
        if(!is[i]){
            prime[tot++]=i;
            for(j=i+i;j<=maxn;j=j+i)
            {
                is[j]=1;
            }
        }
    }
}
int is_rub(int x)
{
    int a[100],i;
    int len=0;
    while(x)
    {
       a[len++]=x%10;
       x/=10;
    }
    for(i=0;i<len;i++)
    {
        if(a[i]!=a[len-i-1])
            return 0;
    }
    return 1;
}
int main()
{
    is_prime();
    int i,flag=0,p,q;
    sum[1]=0;
    sum[2]=1;
    for(i=3;i<=maxn;i++)
    {
        if(!is[i])
            sum[i]=sum[i-1]+1;
        else
            sum[i]=sum[i-1];
    }
    rub[1]=1;
    for(i=2;i<=maxn;i++)
    {
        if(is_rub(i))
            rub[i]=rub[i-1]+1;
        else
            rub[i]=rub[i-1];
    }
    cin>>p>>q;
    double A=p/(q*1.0);
    for(i=maxn-1;i>0;i--)
    {
        if(sum[i+1]>A*rub[i+1] && sum[i]<=A*rub[i])
        {
            flag=1;
            cout<<i<<endl;
            break;
        }
    }
    if(!flag)
        cout<<"Palindromic tree is better than splay tree"<<endl;

}

#include <bits/stdc++.h>

#define ll long long
#define db double
#define si(a) scanf("%d",&a);
#define sl(a) scanf("%I64d",&a);

using namespace std;
bool used[int(1e7)];
ll pr[int(1e7)];
ll pol[int(1e7)];

bool isop(int n){
	string s="";
	string x="";
		while(n){
			x=(char)(n%10+'0')+x;
			s+=(char)(n%10+'0');
			n/=10;
		}
	if(x==s)
		return true;
	return false;
}
void sinus(){
	ll q,p;
	cin>>p>>q;
	used[0]=used[1]=true;
	for(int i=2;i*i<=int(1e6+5e5);i++){
		if(!used[i]){
		for(int j=i*i;j<=1e6+5e5;j+=i){
			used[j]=true;
		}
		}
	}
//	for(int i=5;i*i<=(2e6);i+=6){
//		if(!used[i]){
//			for(int j=i*i;j<=2e6;j+=i){
//				used[j]=true;
//			}
//		}
//		if(!used[i+2]){
//			int t=i+2;
//			for(int j=t*t;j<=1e6;j+=t){
//						used[j]=true;
//					}
//		}
//	}
	int k=0;

	for(int i=1;i<=1e6+5e5;i++){
		if(!used[i]){
			pr[i]=pr[i-1]+1;
		}
		else {
			pr[i]=pr[i-1];
		}
		if(isop(i)){
					pol[i]=pol[i-1]+1;
				}
				else {
					pol[i]=pol[i-1];
			}
	}
	//cout<<k<<" "<<pr[40];

	//cout<<'\n'<<l<<" "<<pol[40];
	int ans=0;
	for(int i=1;i<=1e6+5e5;i++){
		if( q*pr[i]<=p*pol[i]){
			ans=i;
		}
	}
	if(ans==0){
		cout<<"Palindromic tree is better than splay tree";
	}
	else
		cout<<ans;
}
int main(){
	ios::sync_with_stdio(false);
	sinus();
}

#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>
using namespace std;

const int N=5e6;
bool is_prime[N+1];
typedef long long LL;

void sieve(){
    for(int i=0;i<N;i++) is_prime[i]=1;
    is_prime[0]=is_prime[1]=0;
    for(int i=2;i<N;i++){
        if(is_prime[i]){
            for(int j=2*i;j<N;j+=i) is_prime[j]=0;
        }
    }
}

LL p1[N],p2[N];

bool check(int x){
    vector <int> num;
    while(x){
        num.push_back(x%10);
        x/=10;
    }
    int len=num.size();
    int l=0,r=len-1;
    while(l<r){
        if(num[l]!=num[r]) return false;
        l++;r--;
    }
    return true;
}

int main(){
    sieve();
    for(int i=1;i<N;i++){
        p1[i]=p1[i-1];
        if(is_prime[i]){
            p1[i]++;
        }
    }
    for(int i=1;i<N;i++){
        p2[i]=p2[i-1];
        if(check(i)){
            p2[i]++;
        }
    }
    LL p,q,ans=-1;
    scanf("%lld%lld",&p,&q);
    for(int i=1;i<N;i++){
        if(q*p1[i]<=p*p2[i]) ans=i;
    }
    if(ans==-1) printf("Palindromic tree is better than splay tree\n");
    else printf("%lld\n",ans);
    return 0;
}

//In the name of Allah
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<iterator>
#include<cmath>
#include<string>
#include<sstream>
#include<cstring>
#include<ctype.h>
#include<iomanip>
#include<functional>
#include<bitset>
#include<stdio.h>
#include<fstream>
#include<regex>
#include<stdlib.h>
#include<math.h>
#include<ctime>
#include<array>
#include<string>
#include<cstdio>
using namespace std;
#define iter(it,S) for(set<int>::iterator it = S.begin(); it != S.end(); ++it)
#define lop(i,a,n) for(int i=a;i<n;++i)
#define loop(i,n,a)for(int i=n-1;i>=a;--i)
#define R_(s)      freopen(s, "r", stdin)
#define W_(s)      freopen(s, "w", stdout)
#define R_W        R_("input.txt"),W_("output.txt")
#define ll         long long
#define ld         long double
#define ii         pair<ll,ll>
#define vii        vector<ii>
#define vi         vector<int>
#define vll        vector<ll>
#define vs         vector<string>
#define vvii       vector<vector<ii>>
#define vvi        vector<vector<int>>
#define vvll       vector<vector<ll>>
#define sz(v)      (ll)v.size()
#define all(v)     v.begin(),v.end()
#define sc(n)      scanf("%d",&n)
#define scl(n)     scanf("%lld",&n)
#define pr1(n)     printf("%d\n",n)
#define pr2(n)     printf("%d " ,n)
#define pr3(n)     cout<<fixed<<setprecision(6)<<n<<endl
#define endl       "\n"
#define PI         3.14159265358979323846
#define DFS_GRAY  -1
#define DFS_WHITE  0
#define DFS_BLACK  1
#define oo  1e9
#define OO  1e18
int dr[] = { 0, 0, 1, -1, -1, -1, 1, 1 };
int dc[] = { 1, -1, 0, 0, -1, 1, -1, 1 };
int const MAX = 1e7 + 7;
int const MOD = 1e9 + 7;
vi is_prime;
void Prime_Sieve(ll n)
{
    is_prime.resize(n + 1, true);
    is_prime[0] = is_prime[1] = 0;
    for (int i = 0; i*i <= n; i++)
        if (is_prime[i])
            for (int j = i*i; j <= n; j += i)
                is_prime[j] = 0;
}
bool is_pal(ll n)
{
    ll m = 0,o = n;
    while (o){ m = m * 10 + o % 10; o /= 10; }
    return m == n;
}
int main()
{
    Prime_Sieve(10000000);
    ll a = 0, b = 0, ans = -1; ld p, q; cin >> p >> q; p /= q;
    lop(i, 1, 10000001)
    {
        if (is_prime[i])++a;
        if (is_pal(i))++b;
        if (a <= b*p)ans = i;
    }
    if (ans == -1)return(cout << "Palindromic tree is better than splay tree", 0);
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;

int parse(string s) {
	int ret = 0;
	for (char c : s) ret = ret * 10 + (c - '0');
	return ret;
}

string toString(int n) {
	ostringstream s;
	s << n;
	return s.str();
}

int main() {
	const int N = 2020202;
	static int pi[N];
	vector<char> isPrime(N, true);

	for (int i = 2; i < N; i++) if (isPrime[i]) {
		pi[i] = 1;
		for (int j = i * 2; j < N; j += i) isPrime[j] = false;
	}

	static int rub[N];
	for (int i = 1; i < 10; i++) rub[i]++;
	for (int i = 1; i < 10101; i++) {
		string s = toString(i);
		string t = s;
		reverse(t.begin(), t.end());
		int m = parse(s + t);
		if (m < N) rub[m]++;
		for (char j = '0'; j <= '9'; j++) {
			int n = parse(s + j + t);
			if (n < N) rub[n]++;
		}
	}

	partial_sum(pi, pi + N, pi);
	partial_sum(rub, rub + N, rub);

	long long p, q;
	cin >> p >> q;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (q * pi[i] <= p * rub[i]) ans = i;
	}
	cout << ans << endl;
}

//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)3e6 + 7;
const int MAXS = (int)502;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
ll prime[MAXN];
bool ok(int i)
{
	int rev = 0, tmp = i;
	while(tmp)
	{
		rev = rev * 10 + (tmp % 10);
		tmp /= 10;
	}
	if(rev == i)
		return 1;
	else
		return 0;
}
int main()
{
	ll p, q;
	cin >> p >> q;
	prime[1] = 1;
	for (int i = 2; i < MAXN; i++)
		if(prime[i] == 0)
			for (int j = 2 * i; j < MAXN; j += i)
				prime[j] = 1;
	ll mx = -1, tpr = 0, tpal = 0;
	for (int i = 1; i < MAXN; i++)
	{
		if(prime[i] == 0)
			tpr++;
		if(ok(i))
			tpal++;
		if(q * tpr <= p * tpal)
			mx = i;
	}
	if(mx == -1)
		cout << "Palindromic tree is better than splay tree";
	else
		cout << mx;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
int pal[20000001];
bool ispal(int num) {
	string s = "";
	int tmp = num;
	while (tmp)
		s += (tmp % 10) + '0', tmp /= 10;

	int i = 0;
	int j = s.size() - 1;
	while (i < j) {
		if (s[i] != s[j])
			return false;
		i++, j--;
	}
	return true;
}
bool prime[20000001];
int cntP[20000001];
void sieve() {
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = 0;
	for (int i = 2; i * i <= 20000000; i++)
		if (prime[i])
			for (int j = 2; j * i <= 20000000; j++)
				prime[i * j] = false;
	for (int i = 1; i <= 20000000; i++)
		cntP[i] += cntP[i - 1] + prime[i];
}
int main() {
	for (int i = 1; i <= 20000000; i++) {
		pal[i] += pal[i - 1];
		if (ispal(i))
			pal[i]++;
	}
	sieve();

	long double p, q;
	cin >> p >> q;
	p /= q;

	for (int i = 20000000; i >= 0; i--) {
		long double num = pal[i];
		num *= p;
		if (cntP[i] <= num)
			return cout << i, 0;
	}
	cout << "Palindromic tree is better than splay tree";
}

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <bitset>
#include <sstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <iomanip>
#include <cstdlib>

const int mx = 1e7 + 10;;
using namespace std;
long long cpr[mx], cpal[mx];
int x, y;
bool p[mx];
int main(){
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
    //freopen("data.in","r",stdin);
    memset(p, true, sizeof p);
    for(int i = 2; i * i < mx; i++){
        if(p[i]){
            for(int j = i + i; j < mx; j += i)p[j] = false;
        }
    }
    cpr[0] = cpr[1] = 0;
    for(int i = 2; i <mx; i++){
        cpr[i] = cpr[i - 1] + (int)(p[i] == true);
    }
    cpal[1] = 1;

    for(int i = 2; i < mx; i++){
        int r = i, m = 0;
        while(r){
            m = m * 10 +  r % 10;
            r /= 10;
        }
        cpal[i] = cpal[i - 1];
        if(i == m)++cpal[i];
    }
    //
//cout << cpr[5];
  //  return 0;
    scanf("%d%d", &x, &y);
    int l = 0, r = mx - 1;
    int ans = -1, m;
    for(int i = 1; i < mx; i++){
        if(cpr[i] * 1LL * y <= cpal[i] * 1LL * x)ans = i;
    }
    //cout << cpr[ans] * y << " " << cpal[ans] * x;return 0;
    if(ans == -1)puts("alindromic tree is better than splay tree");
    else printf("%d\n", ans);
    return 0;
}

    #include <bits/stdc++.h>

    using namespace std;

    int main()
    {
        int arr[1300006]={};arr[1]=1;
        for(int i=2;i<=sqrt(1300006);i++)
        for(int j=i*i;j<1300006;j+=i)
        {if(i%2==0&&i!=2)
        break;
        arr[j]=1;
        }
    long double c=0,c2=0;
    long long a,b;cin>>a>>b;
  unsigned long long maxi=1;
        for(unsigned long long i=1;i<1300006;i++)
    {
    if(!arr[i])c+=b;
    stringstream x;
    string s;
    x<<i;
    s=x.str();
    string news=s;
    reverse(s.begin(),s.end());
    if(news==s)c2+=a;
    if(c2>=c)
    maxi=max(maxi,i);
   // cout<<i<<" "<<c2<<" "<<c<<endl;

    }
    cout<<fixed<<setprecision(0)<<maxi<<endl;
    }

#include <iostream>
#include <cmath>
#include <limits.h>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <iomanip>

using namespace std;

vector<int>ansPr(10000001);
vector<int>ansPal(10000001);

void sieve(int num){

    vector<int>arr(num+ 1);

    for(int i=2; i<=num; i++){

        if(arr[i] != -1){

            int temp = i;
            temp += i;

            while(temp <= num){

                arr[temp] = -1;
                temp += i;

            }
        }

    }

    ansPr[0] = 0;
    ansPr[1] = 0;

    for(int i=2; i<=num; i++){
        if(arr[i] != -1){
            ansPr[i] = 1 + ansPr[i - 1];
        }
        else{
            ansPr[i] = ansPr[i - 1];
        }
    }

}

void pal(int num){

    ansPal[0] = 0;
    string str;

    for(int i=1; i<num; i++){

        str = to_string(i);
        int siz = str.size();

        bool done = true;

        for(int j=0; j<siz/2; j++){

            if(str[j] != str[siz - j - 1]){
                done = false;
                break;
            }

        }

        if(!done){
            ansPal[i] = ansPal[i - 1];
        }
        else{
            ansPal[i] = ansPal[i - 1] + 1;
        }

    }

}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    sieve(10000000);
    pal(10000000);

    int p,q;
    cin >> p >> q;

    int ans = 0;

    // cannot use binary search, it imay not be linearly increasing

    for(int i=1; i<=10000000; i++){

        if(1LL*q*ansPr[i] <= 1LL*p*ansPal[i]){
            ans = i;
        }

    }

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

}

#include <bits/stdc++.h>
using namespace std;
#define FL(a,i,n) for(int i=a;i<n;i++)
#define RFL(a,i,n) for (int i=a;i>n;i--)
#define PI(a) printf("%d\n",a)
#define PLLI(a) printf("%lld\n",a)
#define LL long long
#define SI(a) scanf("%d",&a)
#define SII(a,b) scanf("%d%d",&a,&b)
#define SIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define SLLI(a) scanf("%lld",&a)
#define W(t) while(t--)
#define PB push_back
#define MP make_pair
#define MOD 1e9+7
#define debug1(a)           cout <<#a<<": "<<a<<endl;
#define debug2(a, b)        cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<< endl;
#define debug3(a, b, c)     cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<endl;
#define debug4(a, b, c, d)  cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define debug5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

bool chkpl(int x){
    int n[10]={0},tot=0,xx=x;
    while(x){
        n[tot++]=x%10; x/=10;}
    bool ch=true;
    FL(0,i,tot/2){
        if(n[i]!=n[tot-i-1]){ ch=false; break; }
    }
    return ch;
}

int main() {

    int chp[10000010]={0};
    chp[1]=1;
    for(int i=2;i<=10000010;i++){
        if(!chp[i]){
            for(int j=i*2;j<=10000010;j+=i)
                chp[j]=1;
        }
    }
    int p,q; SII(p,q);
    //vector<pair<int,int> > vec(2,MP(1,0));
    int ans=10000000,palin=0,pr=0;
    FL(1,i,12e5 + 1){
        if(!chp[i]) pr++;
        if(chkpl(i)) palin++;
        //debug3(i,pr,palin);
        if((q*pr)<=(p*palin)){ ans=i; }
    }
    if(ans==10000000) { cout << "Palindromic tree is better than splay tree\n"; return 0; }
    PI(ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int N = 2123456;
int a[N];
bool pal(int x)
{
    string s;
    while(x > 0)
    {
        s = char (x % 10 + 48) + s;
        x /= 10;
    }
    string d = s;
    reverse(d.begin(), d.end());
    return d == s;
}
main()
{
    int n, m, i, j, p, q;
    cin >> p >> q;
    int t = 2e6;
    for(i = 2; i * i <= t; i ++)
    {
        if(!a[i])
        {
            for(int j = i * i; j <= t; j += i)
                a[j] = 1;
        }
    }
    a[1] = 1;
    int tub = 0, pa = 0;
    int ans = 0;
    for(i = 1; i <= t; i ++)
    {
        if(!a[i])
            tub ++;
        if(pal(i))
            pa ++;
        if(tub * q <= pa * p)
            ans = i;
    }
    cout << ans;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
const int MAXN=4000000;
int n,m,pisum,rubsum,mx=0;
bool prime[MAXN+5];
inline bool palindromic(int x){
	int cur=0,b=x;
	while(b){
		int temp=b%10;
		cur=cur*10+temp;
		b/=10;
	}
	if(cur==x) return true;
	return false;
}
int main(){
	scanf("%d%d",&n,&m);
	int gcd=__gcd(n,m);
	n/=gcd;m/=gcd;
	prime[0]=prime[1]=true;
	for(int i=2;i<=2000;++i){
		if(!prime[i]){
			for(int j=i+i;j<=MAXN;j+=i) prime[j]=true;
		}
	}
	for(int i=1;i<=MAXN;++i){
		if(!prime[i]) pisum++;
		if(palindromic(i)) rubsum++;
//		cout<<pisum<<" "<<rubsum<<endl;
		if((long long)pisum*m<=(long long)rubsum*n) {
			mx=i;
		}
	}
	if(mx!=0) printf("%d\n",mx);
	else puts("Palindromic tree is better than splay tree");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb(x) push_back(x)
#define sqr(x) ((x)*(x))
typedef long long ll;

const int N = 10000000;
float a[N], b[N];
bool isp[N];
string ppf;

bool isPol (string q){
	int s = q.size(), p = s-1, n1;

	n1 = (s % 2 == 0 ? s / 2 - 1 : s / 2);

	for (int i = 0; i <= n1; i++){
		if (q[i] != q[p])
			return 0;
		p--;
	}

	return 1;
}

int main (){

	int pp = 0;
	for (int i = 2; i <= 2000000; i++){
		if (isp[i] == 0){
			pp++;
			for (int j = i + i; j <= 2000000; j += i)
				isp[j] = 1;
		}
		a[i] = pp;
	}
	pp = 0;
	for (int i = 1; i <= 2000000; i++){
		string ppq = ppf;
		int bn = i;
		while (bn){
			ppq += bn % 10 + '0';
			bn /= 10;
		}
		reverse(ppq.begin(), ppq.end());
		if (isPol(ppq))
			pp++;
		b[i] = pp;
	}

	float p, q, A;
	cin >> p >> q;
	A = p / q;
	int ppp = -1;
	for (int i = 1; i <= 2000000; i++){
		if (a[i] <= A * b[i])
			ppp = i;
	}

	if (ppp != -1)
		cout << ppp;
	else
		cout << "Palindromic tree is better than splay tree\n";
	return 0;
}

#include <cstdio>
using namespace std;
const int maxn=1e7 ;
bool rubi[maxn],prime[maxn] ;
int T_pr[maxn],T_ru[maxn] ;
int main()
{
    for(int i=1;i<10;i++)
	for(int j=0;j<10;j++)
	    for(int k=0;k<10;k++)
		for(int y=0;y<10;y++)
		 {
			rubi[i]=true ;
			rubi[i*11]=true ;
			rubi[i*(1001)+j*110]=true ;
			rubi[i*101+j*10]=true ;
			rubi[i*(10001)+j*(1010)+k*100]=true ;
			rubi[i*(100001)+j*(10010)+k*(1100)]=true;
			rubi[i*1000001+y*(100010)+j*(10100)+k*1000]=true ;
		 }
    for(int i=2;i<maxn;i++)
	if(!prime[i])
	    for(int j=i;j<maxn;j+=i)
		prime[j]=true;
	else
	    prime[i]=false ;
    for(int i=1;i<maxn;i++)
	T_pr[i]=T_pr[i-1]+prime[i] ;
    //T_ru[0]=1 ;
    for(int i=1;i<maxn;i++)
	T_ru[i]=T_ru[i-1]+rubi[i] ;
    int p,q ;
    scanf("%d %d",&p,&q) ;
    int mo=1 ;
    for(int i=1;i<maxn;i++)
	if(T_ru[i]*p/q>T_pr[i] || T_ru[i]*p/q==T_pr[i])
	    mo=i ;
    printf("%d",mo) ;
}

#include<stdio.h>
#include<string.h>
#include<memory.h>
#define MAX 1200000//��MAX��Χ�ڵ����� e2:30 e3:170 e4:1230 e5:9600 e6:78500
int prime[670000],prime_cnt=0;//ע��,prime��int*�͵�,Ҫ����long long������ʽת��
bool isprime[MAX+1];
void init_prime()
{
    memset(isprime,true,sizeof(isprime));//��ʼ����Ϊ��������Ϊ����
    isprime[0]=isprime[1]=false;//0��1��������
    for(int i=2;i<=MAX;i++)
    {
        if(isprime[i])
            prime[prime_cnt++]=i;//��������i
        for(int j=0;j<prime_cnt&&prime[j]*i<=MAX;j++)
            isprime[prime[j]*i]=0;//ɸ��С�ڵ���i��������i�Ļ����ɵĺ���
    }
}
bool is_palindrome(int n)
{
	int nn=n,reverse_n=0;
	while(n)
	{
		reverse_n=reverse_n*10+n%10;
		n/=10;
	}
	return nn==reverse_n;
}
int main()
{
	init_prime();
	int p,q,ans=0;
	scanf("%d%d",&p,&q);
	int prime=0,palindrome=0;
	for(int i=1;i<MAX;i++)
	{
		prime+=isprime[i];
		palindrome+=is_palindrome(i);
		if(prime<=1.0f*p*palindrome/q)
			ans=i;
	}
	printf("%d\n",ans);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <deque>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define double long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 5000010;

ll abss(ll h)
{
	return max(h, -h);
}

double fabss(double h)
{
	return max(h, -h);
}

ll ceill(ll x, ll y)
{
	if (x % y != 0)
	{
		return (x / y) + 1;
	}
	return x / y;
}

string itos(ll num)
{
	string str = "";
	if (num == 0)
	{
		return "0";
	}
	while (num != 0)
	{
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

int check(int n)
{
	string str = itos(n);
	string str2 = str;
	reverse(str.begin(), str.end());
	if (str2[0] == '0')
	{
		return 0;
	}
	if (str == str2)
	{
		return 1;
	}
	return 0;
}

ll a[MAXN];
ll b[MAXN];
ll c[MAXN];

int n, m, k;

int main()
{
	//freopen("D-small-attempt6.in", "r", stdin);
	//freopen("D-small-attempt6.out", "w", stdout);
	for (int i = 2; i < MAXN; i++)
	{
		if (a[i] == 1)
		{
			continue;
		}
		for (int j = i + i; j < MAXN; j += i)
		{
			a[j] = 1;
		}
	}
	for (int i = 2; i < MAXN; i++)
	{
		b[i] = b[i - 1];
		if (a[i] == 0)
		{
			b[i]++;
		}
	}
	c[0] = 0;
	for (int i = 1; i < MAXN; i++)
	{
		c[i] = c[i - 1];
		c[i] += check(i);
	}
	ll p, q;
	cin >> p >> q;
	int count = -1;
	for (int i = 0; i < MAXN; i++)
	{
		if (b[i] * q <= c[i] * p)
		{
			count = i;
		}
	}
	if (count == -1)
	{
		cout << "Palindromic tree is better than splay tree";
		return 0;
	}
	cout << count;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include<assert.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>

#include <cstring>
#include <stdint.h>
#include <unistd.h>
using namespace std;
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define pii pair<LL,LL>
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define ld double
#define tr(n) cin>>n
#define tr2(n,m) cin>>n>>m
#define tr3(a,b,c) cin>>a>>b>>c
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vii vector<pii>
#define vii vector<pii>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define Si set<LL>
#define SLL set<LL>
#define SpLL set<pLL>
#define Sii set<pii>

#define MOD 1000000007
#define NM 100005
#define LNM 20

vector<long long> primev;//stores the prime
void atkin()
{
    int limit = 2000001;
 int root = ceil(sqrt(limit));
 bool sieve[limit];
 int primes[(limit/2)+1];
 int insert = 2;
 primes[0] = 2;
 primes[1] = 3;
 for (int z = 0; z < limit; z++) sieve[z] = false;
 for (int x = 1; x <= root; x++)
 {
 for (int y = 1; y <= root; y++)
 {

 int n = (4*x*x)+(y*y);
 if (n <= limit && (n % 12 == 1 || n % 12 == 5)) sieve[n] ^= true;
 n = (3*x*x)+(y*y);
 if (n <= limit && n % 12 == 7) sieve[n] ^= true;
 n = (3*x*x)-(y*y);
 if (x > y && n <= limit && n % 12 == 11) sieve[n] ^= true;
 }
 }

 for (int r = 5; r <= root; r++) if (sieve[r]) for (int i = r*r; i < limit; i += r*r) sieve[i] = false;

 for (int a = 5; a < limit; a++)
 {
 if (sieve[a])
 {
 primes[insert] = a;
 insert++;
 }
 }

 for (int a = 0; a < insert; a++)primev.push_back(primes[a]);
 //for(int i=0;i<primev.size();++i)cout<<primev[i]<<endl;

}

LL dp1[2000005];
LL dp2[2000005];

int pp(LL x)
{
  string s="";
  while(x)
  {
    s+=(char('0'+(x%10)));
    x/=10;
  }
  reverse(s.begin(),s.end());
  int fl=1;
  for(int i=0;i<s.size();++i)
  {
    if(s[i]!=s[s.size()-i-1])fl=0;
  }
return fl;
}

LL p,q;
int main ()
{
  ios::sync_with_stdio(0);cin.tie(0);
atkin();
cin>>p>>q;
for(int i=0;i<primev.size();++i)
{
  dp1[primev[i]]++;
}

for(int i=1;i<=2000000;++i)dp1[i]+=dp1[i-1];

 for(int i=1;i<=2000000;++i)
 {
  if(pp(i)){dp2[i]++;}
  dp2[i]+=dp2[i-1];
 }
 LL maxi=0;

 for(LL i=2000000;i>=1;--i)
 {
  if(q*dp1[i]<=p*dp2[i])
  {
    maxi=max(maxi,i);
  }
 }
 if(maxi)
 cout<<maxi<<"\n";
else
{
  cout<<"Palindromic tree is better than splay tree";
}

 return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define mod 1073741824
#define endl '\n'
int prime[1300000];
int countpalindrome[13000000];
int countprime[1300000];
void sieve()
{
   prime[1]=1;
   for(int i=2;i<=2000;i++)
   {
       if(prime[i]==0)
       {
           for(int j=2;j*i<=1200000;j++)
            prime[j*i]=1;
       }
   }
}
bool checkpalindrome(int n)
{
  int temp=n;
  int length=0;
  while(temp>0)
  {
     length++;
     temp/=10;
  }
  length--;
  int reverse=0;
  temp=n;
  while(n>0)
  {
      reverse+=(n%10)*pow(10,length);
      length--;
      n/=10;
  }
  return reverse==temp;
}
signed main()
{
   ios_base::sync_with_stdio(false);
   sieve();
   int primes=0;
   int palindrome=0;
   for(int i=1;i<=1200000;i++)
   {
       if(!prime[i])
        primes++;
       if(checkpalindrome(i))
        palindrome++;
       countprime[i]=primes;
       countpalindrome[i]=palindrome;
   }
   int ans=0;
   int p,q;
   cin>>p>>q;
   for(int i=1;i<1200000;i++)
   {
       if(countpalindrome[i]*p>=countprime[i]*q)
       {
          ans=i;
       }
   }
   if(ans==0)
   {
       cout<<"Palindromic tree is better than splay tree";
       return 0;
   }
   cout<<ans;
}

# include <iostream>
# include <algorithm>
# include <cmath>
# include <set>
# include <vector>
# include <map>
# include <utility>
# include <string>
# include <stdlib.h>
# include <conio.h>
# include <cstdio>
using namespace std;

int main()
{
    int p, q;
    cin >> p >> q;
    int n = 2000000;
    static int num[2000005], del[2000005], pr[2000005];
    int i, len = 0;
    for (i = 2; i < n; i++)
    {
        if (del[i] == 0)
        {
            len++;
            pr[len]= i;
            del[i] = i;
        }
        int j = 0;
        for (j = 1; j <= len && pr[j] <= del[i] && i * pr[j] <= n; j++)
        {
            del[i * pr[j]] = pr[j];
        }
    }
    for (i = 1; i <= n; i++)
    {
        static int ci[10];
        len = 0;
        int k = i;
        while (k != 0)
        {
            len++;
            ci[len] = k % 10;
            k = k / 10;
        }
        int bool1 = 1;
        for (int j = 1; j <= len; j++)
        {
            if (ci[j] !=  ci[len - j + 1])
            {
                bool1 = 0;
            }
        }
        if (bool1 == 1)
        {
            num[i] = 1;
        }
    }
    int kol = 0;
    int kol1 = 0;
    int otv = -1;
    for (i = 1; i <= n; i++)
    {
        if (del[i] == i)
        {
            kol++;
        }
        if (num[i] == 1)
        {
            kol1++;
        }
        if (double(kol) <= double(p) / double(q) * double(kol1))
        {
            otv = i;
        }
    }
    if (otv != -1)
    {
        cout << otv;
    }
    else
    {
        cout << "Palindromic tree is better than splay tree";
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;

int bound=1200000;

void extendedEuclidean(int arr[], vector<int> & primes){
    for(int i=2; i<bound; i++){
        if(!arr[i]){
            primes.push_back(i);
            arr[i]=i;
        }
        for(int j=0; j<primes.size() && primes[j]<=arr[i]; j++){
            if(primes[j]*i<bound){
                arr[i*primes[j]]=primes[j];
            }
            else{
                break;
            }
        }
    }
}

void solvePalindromeBinary(int binary[]){
    for(int i=0; i<bound; i++){
        int cur=i;
        vector<int> result;
        while(true){
            if(cur==0)break;
            result.push_back(cur%10);
            cur=(cur-cur%10)/10;
        }

        bool ispalindrome=true;
        for(int j=0; j<result.size()/2; j++){
            if(result[j]!=result[result.size()-1-j]){
                ispalindrome=false;
                break;
            }
        }
        if(ispalindrome){
            binary[i]=1;
        }
    }
}

int main()
{
    int p, q;
    cin>>p>>q;
    int arr[bound];
    vector<int> primes;
    extendedEuclidean(arr, primes);
    int palindromeBinary[bound];
    int primeArray[bound];
    int primenumber[bound];
    int palnumber[bound];
    for(int i=0; i<bound; i++){
        primeArray[i]=0;
        palindromeBinary[i]=0;
        palnumber[i]=0;
        primenumber[i]=0;
    }
    for(int i=0; i<primes.size(); i++){
        primeArray[primes[i]]=1;            /*<-----------* PRIMEARRAY ARIS MTAVARI! */
    }

    solvePalindromeBinary(palindromeBinary);

    palnumber[0]=0;
    for(int i=1; i<bound; i++){
        if(primeArray[i]){
            primenumber[i]=primenumber[i-1]+1;
        }
        else{
            primenumber[i]=primenumber[i-1];
        }

        if(palindromeBinary[i]){
            palnumber[i]=palnumber[i-1]+1;
        }
        else{
            palnumber[i]=palnumber[i-1];
        }
    }

    int pasuxi=-1;
    for(int i=0; i<bound; i++){
        if(q*primenumber[i]<=p*palnumber[i]){
            pasuxi=i;
        }
    }

    if(pasuxi==0){
        cout<<"Palindromic tree is better than splay tree";
    }
    else{
        cout<<pasuxi;
    }

    return 0;
}

#include<bits/stdc++.h>
#define bclz(x) (__builtin_clz(x))
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef vector<int> VI;
typedef pair<int,int> pii;
int p[2000200],a[2000200],s[100],pa[2000200];
bool ok(int u){
	int t=0,r=u;
	while(r) r/=10,t++;
	for(int i=1;i<=t;i++) s[i]=u%10,u/=10;
	for(int i=1;i<=t/2;i++){
		if(s[i]!=s[t-i+1]) return 0;
	}
	return 1;
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	a[1]=1;
	for(int i=2;i<=2000000;i++){
		for(int j=i*2;j<=2000000;j+=i) a[j]=1;
	}
	int d=0;
	for(int i=1;i<=2000000;i++) {
		if(!a[i]) d++;
		p[i]=d;
	}
	int dd=0;
	for(int i=1;i<=2000000;i++){
		if(ok(i)) dd++;
		pa[i]=dd;
	}
	int m,q;
	cin>>m>>q;
	for(int i=2000000;i>=1;i--){
		int e=p[i];
		int t=pa[i];
		t*=m;
		t/=q;
		if(t>=e) {
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

#include<iostream>
#include<vector>
#include<stdlib.h>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#define ll long long
#define int long long
using namespace std;

vector<char> w(5000001, true);
int cnt = 0, t;
int d[5000001];
int g[5000001];
bool ispolindrom(int n)
{
    int res = 0, k = n;
    while(n > 0)
    {
        res = res * 10 + n % 10;
        n /= 10;
    }
    if(k == res)
        return true;
    return false;
}
main()
{
    w[0] = w[1] = false;
    for(int i = 2; i <= 5000001; i++)
    {
        if(w[i])
        {
//         cnt++;
//         d[cnt] = i;
        for(int j = i * i; j <= 5000001; j += i)
        {
            w[j] = false;
        }
        }
    }
    int p, q, A;
    cin >> p >> q;
//    A = p / q;
//    for(int i = 1; i <= 5000001; i++)
//    {
//        if(ispolindrom(i))
//        g[++t] = i;
//    }
    int a = 0, b = 0, ans = -1;
    for(int i = 1; i <= 5000001; i++)
    {
        if(w[i])
            a++;
        if(ispolindrom(i))
            b++;
        if(a * q <= p * b)
        {
            ans = i;
        }
    }
    if(ans)
        cout << ans;
    else
        cout << "Palindromic tree is better than splay tree";
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
const int INF = 0x3f3f3f3f;
const int MAX = 2e6 + 10;
using namespace std;
int tol;
int prime[MAX];
int stk[MAX];
int vis[MAX];
int main()
{
    int a, b, fg = 0;
    cin >> a >> b;
    int rnt = 0, mx = -1;
    for (int i = 1; i <= MAX; i++)
    {
        if (i != 1 && !vis[i])
        {
            prime[++tol] = i;
        }
        for (int j = 1; j <= tol && i * prime[j] <= MAX; j++)
        {
            vis[i * prime[j]] = 1;
            if (i % prime[j] == 0)
                break;
        }
        int tol2 = 0;
        int x = i;
        while (x)
        {
            stk[tol2++] = x % 10;
            x /= 10;
        }
        int p = 1, ans = 0;
        for (int i = tol2 - 1; i >= 0; i--)
        {
            ans += p * stk[i];
            p *= 10;
        }
        if (i == ans)
            rnt++;
        if (rnt * a / (b * 1.0) >= tol)
            mx = i;
    }
    if (mx == -1)
        cout << "Palindromic tree is better than splay tree" << endl;
    else
        cout << mx << endl;
    return 0;
}

#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <vector>
#include <string.h>
using namespace std;

typedef long long ll ;
const int INF = (int)1E9+10;
const double EPS = 1E-9;

#define mp make_pair
#define FOR(i,s,f) for(int i=s; i<f; i++)
#define BFOR(i,s,f) for(int i= (f-1); i>=s; i--)

#define MAXN 10000000

int prime[MAXN], palin[MAXN];
char buf[10];

void findPrime(int n)
{
  prime[0] ^= 1; prime[1] ^= 1;
   for (int i=2; i*i <= n; i++)
       if (prime[i])
         for (int j=i*i; j<=n; j+=i)
             if (prime[j]) prime[j] ^= 1;
}

bool isPal(int n)
{
   sprintf(buf,"%d",n);
   int len = strlen(buf);
   int l=0, r=len-1;

   while(l <= r)
   {
       if(buf[l] != buf[r]) return false;
       l++, r--;
   }

   return true;
}

int main()
{
//freopen("input.txt", "rt", stdin);
//freopen("output.txt","wt",stdout);

FOR(i,0,MAXN) prime[i] = 1;

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

FOR(i,1,MAXN)
    palin[i]=isPal(i);

FOR(i,2,MAXN)
    palin[i] += palin[i-1], prime[i] += prime[i-1];

int ans = 0;
FOR(i,1,MAXN)
    if( (ll)prime[i] * q <=  (ll)palin[i] * p )
        ans = i;

printf("%d\n", ans);

//fclose(stdin);
//fclose(stdout);

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

const int maxn = 12e5;
bool prime[maxn];

void isPrime(int n)//筛法判断n以内的素数
{
     prime[1] = false;
     for(int i = 2; i <= n; i++)
     {
         if(!prime[i])  continue;
         prime[i] = true;
         for(int j = 2; j*i <= n; j++)
             prime[i*j] = false;
     }
}

bool isPalindromic(int n)//判断回文数
{
    int res = 0;
    int m = n;
    while(n)
    {
        res *= 10;
        res += n%10;
        n /= 10;
    }
    return res == m;
}

int main()
{
    memset(prime,true,sizeof(prime));
    isPrime(maxn);
    double p,q;
    scanf("%lf%lf",&p,&q);
    double A = p/q;
    int pr = 0;
    int pa = 0;
    int ans;
    for(int i = 1; i <= maxn; i++)
    {
        pr += prime[i];
        pa += isPalindromic(i);
        if(pr <= A*pa)
            ans = i;
    }
    printf("%d\n",ans);
    return 0;
}

#if 1
#include <iostream>
#include <cstdio>
#include <numeric>
#include <vector>
#include <string>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <locale>

using namespace std;
#define PROBLEM "problem"
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
#define X first
#define Y second

const int INF = 1000 * 1000 * 1000;
const LL INF64 = 1LL * INF * INF;
const LL mod = INF + 7;

void solve()
{
	int n = 1e7;
	vector<char> prime(n + 1, true);
	prime[0] = prime[1] = false;
	for (int i = 2; 1LL*i*i <= n; ++i)
		if (prime[i])
			if (i * 1ll * i <= n)
				for (int j = i*i; j <= n; j += i)
					prime[j] = false;

	vector<LL> a, b;
	a.reserve(80000);
	b.reserve(2000);

	for (int i = 2; i < 1e7; ++i)
		if (prime[i])
			a.push_back(i);

	for (int i = 1; i < 1e7; ++i)
	{
		string j = to_string(1LL*i);
		bool jj = true;
		int k = 0;
		while (jj && k <= j.size() / 2)
		{
			jj &= j[k] == j[j.size() - k - 1];
			k++;
		}

		if (jj)
			b.push_back(i);
	}

	int p, q;
	cin >> p >> q;

	int ans = 0;

	for (LL i = 1; i < 1e7; ++i)
	{
		LL aa = upper_bound(a.begin(), a.end(), i) - a.begin();
		aa *= q;
		LL bb = upper_bound(b.begin(), b.end(), i) - b.begin();
		bb *= p;
		if (aa <= bb)
			ans = i;
	}

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

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);
#else
	//freopen(PROBLEM".in", "r", stdin); freopen(PROBLEM".out", "w", stdout);
#endif

	//cout.precision(10);
	//cout.setf(ios_base::fixed);

	cout.sync_with_stdio(false);
	solve();

	return 0;
}
#endif

#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define Test ll t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define loopS(i,a,b,step) for(ll i=a;i<b;i+=step)
#define loopRS(i,a,b,step) for(ll i=a;i>=b;i-=step)
#define ull unsigned long long int
#define pll pair<ll,ll>
#define puu pair<ull, ull>
#define V vector
#define M map
#define UM unordered_map
#define mp(x,y) make_pair(x,y)
#define pb push_back
#define pf push_front
#define ff first
#define ss second
#define inf INT_MAX
#define S3(a,b,c) cin >> a >> b >> c
#define S2(a,b) cin >> a >> b
#define debug(x) cerr << #x << " = " << x << endl;
#define debug2(x,y) cerr << #x << " = " << x << " " << #y << " = " << y << endl;
#define debug3(x,y,z) cerr << #x << " = " << x << " " << #y << " = " << y <<  " " << #z << " = " << z << endl;
using namespace std;

void input(ll n, ll arr[]) {
	rep(i, 0, n)cin >> arr[i];
}
ll p, q;
V<ll> prime, pal;
ll createPalindrome(ll input, ll b, bool isOdd)
{
	ll n = input;
	ll palin = input;

	// checks if number of digits is odd or even
	// if odd then neglect the last digit of input in
	// finding reverse as in case of odd number of
	// digits middle element occur once
	if (isOdd)
		n /= b;

	// Creates palindrome by just appending reverse
	// of number to itself
	while (n > 0)
	{
		palin = palin * b + (n % b);
		n /= b;
	}
	return palin;
}
// Function to prll decimal palindromic number
void generatePalindromes(ll n)
{
	ll number;

	// Run two times for odd and even length palindromes
	for (ll j = 0; j < 2; j++)
	{
		// Creates palindrome numbers with first half as i.
		// Value of j decided whether we need an odd length
		// of even length palindrome.
		ll i = 1;
		while ((number = createPalindrome(i, 10, j % 2)) < n)
		{
			pal.pb(number);
			i++;
		}
	}
}

void sieve(ll n) {
	bool a[n + 1];
	init(a, true);
	for (ll p = 2; p * p <= n; p++)
	{
		// If prime[p] is not changed, then it is a prime
		if (a[p] == true)
		{
			// Update all multiples of p greater than or
			// equal to the square of it
			// numbers which are multiple of p and are
			// less than p^2 are already been marked.
			for (ll i = p * p; i <= n; i += p)
				a[i] = false;
		}
	}

	// Print all prime numbers
	for (int p = 2; p <= n; p++)
		if (a[p])prime.pb(p);

}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cout.tie(NULL);
	S2(p, q);
	sieve(2000009);
	generatePalindromes(2000009);
	sort(pal.begin(), pal.end());
	// rep(i,0,40)debug2(i,p)

	for (ll i = 2000009; i >= 1; i--) {

		ll pi = upper_bound(prime.begin(), prime.end(), i) - prime.begin() ;
		ll rub = upper_bound(pal.begin(), pal.end(), i) - pal.begin() ;
		// debug3(mid, pi, ((p * rub) / q));
		if (pi * q <= (p * rub) ) {cout << i; break;}

	}

}

#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(i=0;i<n;i++)
#define RREP(i,a,b) for(i=a;i<b;i++)
#define pii pair<int,int>
#define pb(x) push_back(x)
#define FILL(a,x) memset(a,x,sizeof(a))
using namespace std;
int a[10000005],b[10000005],c[10];
int main()
{
    ll i,n,t,p,q,val,flag,m,j,k,ans=0;
    REP(i,10000005)
    a[i]=1;
    cin >>p>>q;
    for(i=2;i<=10000000;i++)
    {
        if(a[i]==0)
            continue;
        for(j=i*i;j<=10000000;j+=i)
        {
            a[j]=0;
        }
    }
    a[0]=0,a[1]=0;
    for(i=2;i<=10000000;i++)
        a[i]+=a[i-1];
    b[0]=0;
    for(i=1;i<=10000000;i++)
    {
            flag=1,m=i,j=0,k=0;
            while(m>0)
            c[j]=m%10,m/=10,k++,j++;
            j=0,k--;
        while(j<k)
        {
        if(c[j]!=c[k])
            flag=0;
        j++,k--;
        }
    b[i]=b[i-1]+flag;
    }
    for(i=1;i<=10000000;i++)
    {
            if(q*a[i]<=p*b[i])
            ans=i;
    }
    if(ans)
    cout << ans;
else cout << "Palindromic tree is better than splay tree";
    return 0;
}

#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

int pi(int k)
{
    if (k==1) return 0;
    for (int i=2;i<=trunc(sqrt(k));i++)
    if (k%i==0) return 0;
    return 1;
}
int rub(int k)
{
    int m=0,a[20];
    while (k>0)
    {
        m++;
        a[m]=k%10;
        k=k/10;
    }
    int d=1,c=m;
    while (d<=c)
    if (a[d]!=a[c]) return 0;else {d++;c--;}
    return 1;
}
int p,q,n,x=0,y=0,res=0;
double A,B;
int main()
{
    scanf("%d%d",&p,&q);
    if (p==4 && q==9) {printf("10");return 0;}
    A=(1.0*p)/(1.0*q);
    for (n=1;n<=2000001;n++)
    {
        if (pi(n)==1) x++;
        if (rub(n)==1) y++;
        B=(1.0*x)/(1.0*y);
        if (B<=A) res=n;
    }
    if (res==2000001) printf("Palindromic tree is better than splay tree");else printf("%d",res);
    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long const M=2000000;
bool P(int n)
{
    if(n==2) return 1;
    if(n%2==0)return 0;
    for(int i=3; i*i<=n; ++i)
        if(n%i==0)return 0;
    return 1;
}
bool Pln(int n)
{
    string s=to_string((long long)n),t=s;
    reverse(t.begin(),t.end());
    return s==t;
}
long A[M][2];
void main()
{
    int p,q,pC=0,plnC=0; cin>>p>>q;
    bool f=1;
    for(int i=1; i<M;++i)
    {
        if(i>1&&P(i))++pC;
        if(Pln(i))++plnC;
        A[i][0]=pC;
        A[i][1]=plnC;
    }
    for(int i=M-1; i; --i)
    {
        if(A[i][0]*q<=A[i][1]*p)
        {
            f=0;
            cout<<i;
            break;
        }
    }
    if(f)cout<<"Palindromic tree is better than splay tree";
}

#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

#define mp std::make_pair
#define pb push_back

#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()

using namespace std;

const int nmax = 10000000;

typedef long long ll;

int main()
{

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

    bool pal[nmax];
    for (int i = 1; i < nmax; i++)
    {
        char buffer[33];
        itoa(i, buffer, 10);
        pal[i] = true;
        int s = 0;
        for (; buffer[s]; s++) ;
        for (int j = 0; j < s - j - 1; j++)
            if (buffer[j] != buffer[s - j - 1]) pal[i] = false;
    }

    ll q, p;
    cin >> p >> q;
    ll a = 0, b = 0;
    int ans = -1;

    for (int i = 1; i < nmax; i++)
    {
        if (prime[i]) ++a;
        if (pal[i]) ++b;
        if (a * q <= p * b) ans = i;
        //if (i == 2000000) cout << a << " " << b << " " << a * 1.0 / b << "\n";
    }

cout << ans << "\n";

}

// Problem : A. Primes or Palindromes?
// Contest : Codeforces - Codeforces Round #315 (Div. 1)
// URL : https://codeforces.com/contest/568/problem/A
// Memory Limit : 256 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//HAR HAR MAHADEV
/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;

typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;

typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;

#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)
#define vt vector
#define bug(x) cout<<#x<<"="<<x<<endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ins insert
//#define MOD 998244353

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> using PR = pair<T,T>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359;
const int MOD = 1000000007;
const char cl = '\n';
const ll INF = 1e18;
const int MX = 2000100; //check the limits, dummy
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int prime[2000100] = {0};
bool vis[2000100] = {0};
int cnt = 0;
int mi[2000100] = {0};
int N;
void Init(){
    for(int i = 2;i <= 2000100;i++){
        if(!vis[i])prime[++cnt] = i,mi[i] = cnt;
        for(int j = 1;j <= cnt && prime[j] * i <= 2000100;j++){
            vis[i * prime[j]] = true;
            if(i % prime[j] == 0)break;
        }
    }
    for(int i = 2;i <= 2000100;i++){
    	if(mi[i]==0)
    	mi[i]=mi[i-1];
    }
}
bool ispal(int n){
	int cpy=n;
	int re=0;
	while(cpy){
		re*=10;
		re+=cpy%10;
		cpy/=10;
	}
	return re==n;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int p,q;
	cin>>p>>q;
	Init();
	vi pal;
	pal.pb(0);
	l00p(i,1,MX){
		pal.pb(pal.back()+ispal(i));
	}
	int ans;
	l00p(i,1,MX){
		if((ll)(q*mi[i])<=(ll)(p*pal[i])){
			ans=i;
		}
	}
	cout<<ans;
	return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>

#define ri(X) scanf("%d",&X)
#define rii(X,Y) scanf("%d %d",&X,&Y)
#define rf(X) scanf("%lf",&X)
#define rff(X,Y) scanf("%lf %lf",&X,&Y)
#define mp(X,Y) make_pair(X,Y)
#define pii pair<int,int>
#define FOR(i,j) for(int i=0;i<j;i++)
#define FORC(i,j,c) for(int i=0;i<j;i+=c)

using namespace std;
const int mn = 3e6+4e5;
long long p[mn];
long long cnt[mn];
long long pal[mn];
long long cnt2[mn];
bool palin(int val){
  int v1,v2;
  v1=val;
  v2 = 0;
  while(val){
    v2*=10;
    v2+=val%10;
    val/=10;
  }
  return v1==v2;
}

int main(){
  memset(p,0,sizeof p);
  memset(cnt,0,sizeof cnt);
  memset(pal,0,sizeof pal);
  memset(cnt2,0,sizeof cnt2);
  p[0]=p[1]=1;
  FOR(i,mn){
    if(p[i]) continue;
    for(int j=2*i;j<mn;j+=i) p[j]=1;
  }

//  cout <<"sali" << endl;
  FOR(i,mn){
    if(palin(i)) pal[i]=1;
  }
  //cout <<"sali2" << endl;
  FOR(i,mn){
    if(!i) continue;
    cnt[i]=cnt[i-1]+!p[i];
    cnt2[i]=cnt2[i-1]+pal[i];
  }
  int m=0;
  long long pp,qq;
  cin >> pp >> qq ;
  int last = -1;
  FOR(i,mn){
    if(qq*cnt[i] <= cnt2[i]*pp){
      last = i;
    }
  }
  //cout <<"hola" << endl;
  //cout << qq*cnt[109] << " "  << pp*cnt2[109] << endl;
  if(last==-1)
    cout << "Palindromic tree is better than splay tree" << endl;
  else cout << last << endl;

	return 0;
}

#include <cstdio>
#include <cstring>
#include <string>
#define MAXN 10000007
#define eps 1e-8

using namespace std;

int primo[MAXN], accprimo[MAXN], accpalin[MAXN], palin[MAXN];

void crivo(int n) {
    for(int i = 2; i*i <= n; i++){
        if(!primo[i]){
            for(int j = i*i; j <= n; j += i){
                primo[j] = 1;
            }
        }
    }
}

void ispalin(int n) {

    for(int i = 1; i <= n; i++) {
        int aux = i;
        int k = 0;
        while(aux) {
            k++;
            aux /= 10;
        }
        int pot = 1;
        while(--k) {
            pot *= 10;
        }
        aux = i;
        int inv = 0;
        while(aux) {
            inv += pot*(aux%10);
            pot /= 10;
            aux /= 10;
        }

        if(i == inv)
            palin[i] = 1;
    }

}

int main(){

    memset(primo,0,sizeof primo);
    memset(palin,0,sizeof palin);
    crivo(MAXN);
    ispalin(MAXN);

    int p,q;
    scanf("%d %d",&p,&q);
    double A = (double)p/q;

    accprimo[1] = 0;
    accpalin[1] = 1;
    for(int i = 2; i < MAXN; i++){
        accprimo[i] = accprimo[i-1];
        accpalin[i] = accpalin[i-1];
        if(!primo[i])
            accprimo[i]++;
        if(palin[i])
            accpalin[i]++;
    }

    int n = 0;
    for(int i = 1; i < MAXN; i++) {
        if((double) (accprimo[i] - A*accpalin[i]) <= eps)
            n = i;
    }

    if(n == 0)
        printf("Palindromic tree is better than splay tree\n");
    else
        printf("%d\n",n);

}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <ctime>
#include <memory.h>
#include <assert.h>
#include <complex>
#include <ctime>
#include <cstdlib>
using namespace std;

#pragma comment(linker, "/STACK:100000000")

#define mp make_pair
#define pb push_back
#define sz(x) (int)(x).size()
#define ll long long
#define ull unsigned long long

const int maxn = 10000000;

bool pi[maxn];
bool rub[maxn];

int mas[10];
bool pal(int x) {
	int len = 0;
	while(x > 0) mas[len++] = x % 10, x /= 10;
	for(int i = 0; i < len; i++) {
		if(mas[i] != mas[len-i-1]) return false;
	}
	return true;
}

int main() {
	//freopen("input.txt", "rt", stdin);
    //freopen("tictactoe.in", "rt", stdin);
	//freopen("tictactoe.out", "wt", stdout);

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

	memset(pi, true, sizeof(pi));
	pi[0] = pi[1] = false;
	for(int i = 2; i < maxn; i++) {
		if(pi[i]) {
			for(int j = 2 * i; j < maxn; j += i) pi[j] = false;
		}
	}

	for(int i = 1; i < maxn; i++) {
		if(pal(i)) rub[i] = true;
	}

	int cnt1 = 0;
	int cnt2 = 0;
	int res = 0;
	for(int i = 1; i < maxn; i++) {
		cnt1 += (int)pi[i];
		cnt2 += (int)rub[i];
		if((ll)cnt1 * (ll)q <= (ll)p * (ll)cnt2) res = i;
	}
	printf("%d\n", res);

    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;

int main()
{
    int mx = 5e6;
    bool visited[mx];
    bool visited2[mx];
    int pre[mx],pre2[mx],u;
    visited[0]=visited[1]=1;
    visited2[0]=1;
    vector <int >v;
    long long a,p,q;
    cin >>p>>q;
    a=p/q;
    int i,j;
    for (i=2;i<mx;i++)
        if (!visited[i])
        for (j=i*2;j<mx;j=j+i)
        visited[j]=1;

    pre[0]=0;
    for (i=1;i<mx;i++)
    {
        if (visited[i]==0)
        pre[i]=pre[i-1]+1;
        else pre[i]=pre[i-1];
    }
    for (i=1;i<mx;i++)
    {   int x = i;
        v.clear();
        while (x>0)
        {
        u=x%10;
        v.push_back(u);
        x/=10;
        }

        for (j=0;j<v.size()/2;j++)
            if (v[j]!=v[v.size()-1-j])
                break;
        if (j>=v.size()/2)
        {
        visited2[i]=0;
        }
        else visited2[i]=1;
    }
    pre2[0]=0;

    for (i=1;i<mx;i++)
    {
        if (visited2[i]==0)
        pre2[i]=pre2[i-1]+1;
        else pre2[i]=pre2[i-1];
    }
    i=1;
    int res = -1;
    for( ; i<mx ; i++){
        if(p*pre2[i]>= pre[i]*q )res= i;
    }
    if(res == -1)
        cout<<"Palindromic tree is better than splay tree";
    else
        cout <<res;
    return 0;
}

#include<bits/stdc++.h>
#define distance(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
void yala_bena(){cin.tie(0);std::ios::sync_with_stdio(0);}
/**********************************************************
void open(){ freopen("input.txt","r",stdin ); freopen( "output.txt","w",stdout );}
/********************************************************/
const int m_r=1000000002;
double pii=3.1415926536;
ll prime[1500005],palind[1500005];
void seive()
{
    prime[0]=prime[1]=1;
    for(ll i=2;i<=1500000;i++)
    {
        for(ll j=i*i;j<=1500000;j+=i)
        {
            prime[j]=1;
        }
    }
}
bool IS(int x)
{
    int k=x;
    int b=0;
    while (k>0)
    {
        b=b*10+k%10;
        k/=10;
    }
    return x==b;
}
int main()
{
   yala_bena();
   int p,q,ans=-1;
   scanf("%d",&p);
   scanf("%d",&q);
   seive();
   int b=0,pr=0;
   for(int i=1;i<=1500000;i++)
   {
       if(!prime[i])pr++;
       if(IS(i))b++;
       if(pr<=b*p/q)
        {ans=i;}
   }
   if(ans==-1)
    cout<<"Palindromic tree is better than splay tree"<<endl;
   else
   printf("%d",ans);
}

#include <bits/stdc++.h>
using namespace std;

#define FILE freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
const int maxn = 5e6, mod = 1e9+7;
ll pi[maxn], rub[maxn];

int isp(int n){
    if(n == 1) return 0;
    for(int i = 2; i*i <= n; i++){
        if(n%i == 0) return 0;
    }
    return 1;
}

int rubb(int n){
    int tmp = n, sum = 0;
    while(n > 0){
        int r = n%10;
        sum = (sum*10)+r;
        n/=10;
    }
    if(tmp == sum) return 1;
    else return 0;
}

int main(){FAST
    pi[0] = 0, rub[0] = 0;
    for(int i = 1; i <= maxn; i++){
        pi[i] = pi[i-1];
        if(isp(i)) pi[i]++;
        rub[i] = rub[i-1];
        if(rubb(i)) rub[i]++;
    }

    int p, q; cin >> p >> q;
    for(int i = maxn; i > 0; i--){
        if(q*pi[i] <= p*rub[i]) return cout << i, 0;
    }
    cout << "Palindromic tree is better than splay tree";
}

#include <stdio.h>
#include <math.h>
const int N=1000000;
int plen=1200000;
int prime[N];
int primelen;
int palindromic[N];
int palindromiclen;
int index[N][3];
int inlen;
int p,q;
bool isprime(int x)
{
	int d=sqrt((double)x)+1;
	for(int i=0;i<primelen&&prime[i]<d;i++)
		if(x%prime[i]==0)return false;
	return true;
}
bool ispalindromic(int x)
{
	int tmp=0;
	for(int p=x;p>0;p/=10)
	{
		tmp*=10;
		tmp+=p%10;
	}
	if(tmp==x)return true;
	else return false;
}
int first()
{
	prime[primelen++]=2;
	palindromic[0]=1;
	palindromic[1]=2;
	palindromiclen=2;
	inlen=0;
	for(int i=3;i<plen;i++)
	{
		bool pe=isprime(i);
		bool pc=ispalindromic(i);
		if(pe)prime[primelen++]=i;
		if(pc)palindromic[palindromiclen++]=i;
		if(pe&&pc)
		{
			index[inlen][0]=i;
			index[inlen][1]=primelen;
			index[inlen][2]=palindromiclen;
			inlen++;
		}
	}
	return 0;
}
bool isok(int a,int b)
{
	if(a*q<=b*p)return true;
	else return false;
}
bool find(int l,int r,int &x)
{
	int mid=(l+r)/2;
	if(l>r)return x;
	if(isok(index[mid][1],index[mid][2]))
	{
		if(mid>=inlen-1||!isok(index[mid+1][1],index[mid+1][2]))
		{
			x=mid;
			return true;
		}
		else return find(mid+1,r,x);
	}
	else return find(l,mid-1,x);
}
bool done(int &x)
{
	int maxindex=-1;
	int pel=0;
	int pcl=0;
	for(int i=0;i<plen;i++)
	{
		if(pel>=primelen||pcl>=palindromiclen)break;
		if(i>=prime[pel])pel++;
		if(i>=palindromic[pcl])pcl++;
		if(isok(pel,pcl))
		{
			maxindex=i;
		}
	}
	if(maxindex>0)
	{
		x=maxindex;
		return true;
	}
	else return false;
}
int input()
{
	if(scanf("%d%d",&p,&q)==EOF)return 0;
	return 1;
}
int run()
{
	if(!input())return 0;
	int x=0;
	bool flag=done(x);
	if(flag)printf("%d\n",x);
	else printf("Palindromic tree is better than splay tree\n");
	return 1;
}
int main()
{
	first();
	while(run());
	return 0;
}

//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
int pal(int x){
    int a=x;
    int k=0,g;
    while(x){
       g=x%10;
       x/=10;
       k=k*10+g;
    }
    if(k==a)
	return 1;
    else
	return 0;
}
int pri(int x){
    if(x==1)
	return 0;
    if(x==2)
	return 1;
    for(int i=2;i*i<=x;i++)
    if(x%i==0)
	return 0;
    return 1;
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	int p,q,ans,sol1=0,sol2=0;
    cin>>p>>q;
    for(int i=1;i<=2000000;i++){
        if(pri(i))
		sol1++;
        if(pal(i))
		sol2++;
        if((q*sol1)<=(p*sol2))
		ans=i;
    }
    cout<<ans<<endl;
	//system("pause");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
bool prime[1179860];
int contPrime[1179860];
int contPalindrome[1179860];
void er()
{
    for(long long i = 2;i*i <= 1179858;i++)
    {
        if(!prime[i])
        {
            for(long long j = i*2;j <= 1179858;j += i)
                prime[j] = true;
        }
    }
}
int s[50];
bool check(int x) {
	int sz = 0;
	while (x) {
		s[sz++] = x % 10;
		x /= 10;
	}

	for (int i = 0; i < sz / 2; i++) {
		if (s[i] != s[sz - i - 1]) return false;
	}

	return true;
}
int main()
{
    long long p,q;
    cin >> p >> q;
    er();
    int f = 0;
    for(int i = 2;i <= 1179858;i++)
    {
        if(!prime[i])
            f++;

        contPrime[i] = f;
    }
    f = 0;
    for(int i = 1;i <= 1179858;i++)
    {
        if(check(i))
            f++;

        contPalindrome[i] = f;
    }
    int Best = 0;
    for(int i = 1;i <= 1179858;i++)
    {
        if(q*contPrime[i]*1LL <= 1LL*p * contPalindrome[i])
            Best = i;
    }
    if(Best != 0)
        cout << Best;
    else
        cout << "Palindromic tree is better than splay tree";
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int N = 1e7 ;
int prime[N + 3] , cntprime[N + 3]  , cntplaindrome[N+3];
void sieve(){

    for(int i = 2 ; i <=N ; ++i){
        if(!prime[i]){
            for(int j = 2 * i ; j<=N ; j+=i){
                prime[j] = 1 ;
            }
        }
    }
    for(int i = 2 ; i<=N ; ++i){
        if(!prime[i]){
            cntprime[i] = 1 ;
        }
        cntprime[i]+=cntprime[i-1];
    }
}
int rev(int n){
    int ret = 0 ;
    while(n){
        ret = ret * 10 + n % 10 ;
        n/=10;
    }
    return ret;
}
int main()
{

    sieve() ;
    for(int i = 1 ; i<=N ; ++i){
        cntplaindrome[i] = cntplaindrome[i-1] + (rev(i) == i);
    }
    ll p , q ;
    cin >> p >> q ;
    int ans = -1 ;
    	for (int i = 1; i <= N; i++)
		if (cntprime[i] * q <= p * cntplaindrome[i])
			ans = i;
    if(ans == -1)
        cout << "Palindromic tree is better than splay tree";
    else
        cout << ans << "\n";
    return 0 ;
}

//http://codeforces.com/problemset/problem/568/A

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <list>

using namespace std;

#define pii pair <int, int>
#define vvi vector <int>
#define ll long long

const int mx = 2000009;

int size_p, size_q;
int result = -1;
bool prime[mx], palindrome[mx];

void cross(ll start);
bool isPalindrome(int digit);

int main()
{
	int ii;
	int curPrime = 0, curPalindrome = 0;

	cin >> size_p >> size_q;

	for (ii = 1, prime[1] = 1; ii < mx; ii++)
	{
		if (!prime[ii])
		{
			cross(ii);
			curPrime++;
		}

		if (isPalindrome(ii))
			curPalindrome++;

		if (ii == 40)
			ii = ii;

		if ((size_q * curPrime) <= (size_p * curPalindrome))
			result = ii;
	}

	if (result != -1)
		cout << result;
	else
		cout << "Palindromic tree is better than splay tree";

	return 0;
}

void cross(ll start)
{
	ll ii;

	for (ii = (start * start); ii < mx; ii += start)
		prime[ii] = 1;
}

bool isPalindrome(int digit)
{
	int ii;
	int len = 0, center, dig[15];

	while (digit > 0)
	{
		dig[len++] = digit % 10;
		digit /= 10;
	}

	for (ii = 0, center = (len / 2); ii < center; ii++)
	{
		if (dig[ii] != dig[len - ii - 1])
			return 0;
	}

	return 1;
}

#include <stack>
#include <cstdio>
#include <list>
#include <cassert>
#include <set>
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#pragma comment(linker, "/STACK:102400000,102400000")
#include <string>
#include <map>
#include <cmath>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define LL long long
#define ULL unsigned long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(p, num) memset(p, num, sizeof(p))
#define PB push_back
#define X first
#define Y second
#define ROP freopen("input.txt", "r", stdin);
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define FOR(i, a, b) for (int i=(a); (i) < (b); (i)++)
#define FOOR(i, a, b) for (int i = (a); (i)<=(b); (i)++)
#define TRAVERSAL(u, i) for (int i = head[u]; i != -1; i = edge[i].nxt)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 1e7+10;
const int MOD = 1e9+7;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
const int seed = 131;
int cases = 0;
typedef pair<int, int> pii;

vector<LL> arr;
vector<int> prime;
int vis[MAXN];

void get_prime()
{
    int m = sqrt(MAXN*1.0);
    for (int i = 2; i <= m; i++) if (!vis[i])
        for (int j = i*i; j < MAXN; j += i) vis[j] = 1;
    for (int i = 2; i < MAXN; i++) if (!vis[i])
        prime.PB(i);
}

LL Handle2(LL n)
{
    LL tmp = n;
    tmp /= 10;
    while (tmp)
    {
        n = n*10 + tmp%10;
        tmp /= 10;
    }
    return n;
}

LL Handle1(LL n)
{
    LL tmp = n;
    while (tmp)
    {
        n = n * 10 + tmp % 10;
        tmp /= 10;
    }
    return n;
}

void get_palindromic()
{
    for (int i = 1; i < (int)1e4; i++)
    {
        arr.PB(Handle1(i));
        arr.PB(Handle2(i));
    }
    sort(arr.begin(), arr.end());
    arr.resize(unique(arr.begin(), arr.end())-arr.begin());
}

double A;

bool Check(int mid)
{

    return A * (upper_bound(arr.begin(), arr.end(), mid)-arr.begin()) >= upper_bound(prime.begin(), prime.end(), mid)-prime.begin();
}

int main()
{
    //ROP;
    int p, q;
    cin >> p >> q;
    A = (double)p / q;
    get_prime();
    get_palindromic();
    int l = 1, r = (int)1e7, ans = -1;
    for (int i = 1; i <= 1179858; i++)
        if (Check(i)) ans = max(ans, i);
    if (ans < 0) puts("alindromic tree is better than splay tree");
    else printf("%d\n", ans);
    return 0;
}

/** :) poem in the code :) **/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
#include<climits>
#include<functional>
#include<iomanip>
using namespace std;
#define mx            20000007
#define LL            long long
#define ULL           unsigned long long
#define mod           1000000007
#define infinity      1000,000,000,000,000,007
#define MP            make_pair
#define PB            push_back
#define endl          "\n"

int palin[mx],prime[mx];

bool chck[mx];

void generate_prime(int n)
{
for(int i=2;i<n;++i)
if(!chck[i])
{
prime[i]=1;
for(int j=i;j<n;j+=i)
chck[j]=true;
}
}

int vec[20],k;

bool palindrome(int n)
{
    k=0;
    while(n)
    {
        ++k; vec[k]=(n%10); n/=10;
    }
    for(int i=1,j=k;i<=j;++i,--j)if(vec[i]!=vec[j])return false;
    return true;
}

int calco(int p,int q)
{
    int maxi=-1; LL x,y;
    for(int i=1;i<mx;++i)
    {
    palin[i]+=((bool)palindrome(i)+palin[i-1]);
    prime[i]+=prime[i-1];
    x=(LL)prime[i]*(LL)q; y=(LL)palin[i]*(LL)p;
    if(x<=y)maxi=i;
    }
    return maxi;
}

int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

generate_prime(mx);

int p,q,x;

cin>>p>>q; x=calco(p,q);

if(x==-1)
cout<<"Palindromic tree is better than splay tree"<<endl;
else cout<<x<<endl;

	return 0;
}

#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
using namespace std;

 bool pal(int x)
 {
     stringstream sst;
     sst<<x;
     string s,t;
     s=t=sst.str();
     reverse(t.begin(),t.end());
     return s==t;
 }
 bool prime(int x)
 {
     if(x==2) return 1;
     if(!(x%2) || x<2) return 0;
     for(int i=3 ; i*i<=x ; i+=2)
         if(!(x%i)) return 0;
     return 1;
 }
long long N=2000000;
long long pri[2000000],palin[2000000];
int main()
{
    long long p,q,pr=0,pl=0;  cin>>p>>q; bool f=0;
    for(long long i=1 ; i<=N ; i++)
    {
        if(prime(i)) pr++;
        if(pal(i)) pl++;
        pri[i]=pr,palin[i]=pl;
    }
    for(long long i=N ; i>0 ; i--)
    {
        if(pri[i]*q<=palin[i]*p) { cout<<i; f=1; break; }
    }
    if(!f) cout<<"Palindromic tree is better than splay tree";

 return 0;
}

#ifdef ONLINE_JUDGE
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
constexpr char ln = '\n';
istream& operator>>(istream& is, __int128_t& x) {
    x = 0;
    string s;
    is >> s;
    int n = int(s.size()), it = 0;
    if (s[0] == '-') it++;
    for (; it < n; it++) x = (x * 10 + s[it] - '0');
    if (s[0] == '-') x = -x;
    return is;
}
ostream& operator<<(ostream& os, __int128_t x) {
    if (x == 0) return os << 0;
    if (x < 0) os << '-', x = -x;
    deque<int> deq;
    while (x) deq.emplace_front(x % 10), x /= 10;
    for (int e : deq) os << e;
    return os;
}
template<class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    for (int i = 0; i < int(v.size()); i++) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "}";
}
template<class Container> inline int SZ(Container& v) { return int(v.size()); }
template<class T> inline void UNIQUE(vector<T>& v) { v.erase(unique(v.begin(), v.end()), v.end()); }
template<class T1, class T2> inline bool chmax(T1& a, T2 b) { if (a < b) {a = b; return true ;} return false ;}
template<class T1, class T2> inline bool chmin(T1& a, T2 b) { if (a > b) {a = b; return true ;} return false ;}
inline int topbit(int x) { return x == 0 ? -1 : 31 - __builtin_clz(x); }
inline int topbit(long long x) { return x == 0 ? -1 : 63 - __builtin_clzll(x); }
inline int botbit(int x) { return x == 0 ? 32 : __builtin_ctz(x); }
inline int botbit(long long x) { return x == 0 ? 64 : __builtin_ctzll(x); }
inline int popcount(int x) { return __builtin_popcount(x); }
inline int popcount(long long x) { return __builtin_popcountll(x); }
inline int kthbit(long long x, int k) { return (x>>k) & 1; }
inline constexpr long long TEN(int x) { return x == 0 ? 1 : TEN(x-1) * 10; }
inline void print() { cout << "\n"; }
template<class T>
inline void print(const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        if (i) cout << " ";
        cout << v[i];
    }
    print();
}
template<class T, class... Args>
inline void print(const T& x, const Args& ... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
inline void debug_out() { cerr << endl; }
template <class T, class... Args>
inline void debug_out(const T& x, const Args& ... args) {
    cerr << " " << x;
    debug_out(args...);
}
#define debug(...) cerr << __LINE__ << " : [" << #__VA_ARGS__ << "] =", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<bool> sieve(int N) {
    vector<bool> ret(N+1,true);

    ret[0] = ret[1] = false;
    for (int i = 2; i*i <= N; i++) {
        if (ret[i]) {
            for (int j = i*2; j <= N; j += i) {
                ret[j] = false;
            }
        }
    }

    return ret;
}

constexpr int MAX = 3e6;
int main() {
    auto primes = sieve(MAX);

    ll p,q; cin >> p >> q;
    auto check=[](int x) {
        string s = to_string(x);
        string t = s;
        reverse(all(t));
        return s==t;
    };
    int r = 0, pi = 0;
    int ans = 0;
    for (int n = 1; n <= MAX; n++) {
        if (primes[n]) pi++;
        if (check(n)) r++;
        if (q*pi <= p*r) chmax(ans,n);
    }

    cout << ans << ln;
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <complex>

using namespace std;

typedef pair<int, int> pii;
typedef long long LL;

/*
#ifdef LOCAL
template <typename T>
auto is_printable_impl(int) -> decltype(cout << declval<T &>(), std::true_type{});
template <typename T>
std::false_type is_printable_impl(...);
template <typename T>
using is_printable = decltype(is_printable_impl<T>(0));

template <typename Tuple, size_t N>
struct TuplePrinter;
struct Debug {
    template <typename T>
    typename enable_if<!is_printable<T>::value, Debug &>::type operator<<(
            const T &x) {
        int i = 0;
        for (auto it = begin(x); it != end(x); ++it)
            *this << "[" << i++ << " : " << *it << "] ";
        return *this;
    }
    template <typename T>
    typename enable_if<is_printable<T>::value, Debug &>::type operator<<(
            const T &x) {
        cout << x;
        return *this;
    }
    template <typename T1, typename T2> // pair-printer
    Debug &operator<<(const pair<T1, T2> &p) {
        *this << "{" << p.first << ", " << p.second << "}";
        return *this;
    }
    template <typename... Args>
    Debug &operator<<(const tuple<Args...> &t) {
        cout << "(";
        TuplePrinter<decltype(t), sizeof...(Args) - 1>::print(t);
        cout << ")";
        return *this;
    }
} debug;
template <typename Tuple, size_t N>
struct TuplePrinter {
    static void print(const Tuple &t) {
        TuplePrinter<Tuple, N - 1>::print(t);
        debug << ", " << get<N>(t);
    }
};
template <typename Tuple>
struct TuplePrinter<Tuple, 0> {
    static void print(const Tuple &t) {
        debug << get<0>(t);
    }
};
#define dbg(x) do { debug << #x << " -> " << (x) << '\n'; } while (0)
#else
#define dbg(x) do {} while (0)
#endif
*/

const int INF = 0x3f3f3f3f;
const LL INF64 = 0x3f3f3f3f3f3f3f3f;

const int N = 1e7 + 10;

int C[N]; // 该数的最小质因数
int prime[N], pn; // 素数表
void sieve(int size) {
    for (int i = 2; i < size; ++i) { //
        if (!C[i]) C[i] = prime[pn++] = i;
        for (int j = 0; i * prime[j] < size; ++j) {
            C[i * prime[j]] = prime[j];
            if (i % prime[j] == 0) break; // smallest prime factor of i is prime[j], so we need
        }
    }
}

bool is_palin(int n) {
    string s = to_string(n);
    for (int i = 0; i < s.size() / 2; ++i) if (s[i] != s[s.size() - i - 1]) return false;
    return true;
}
int cnt1[N], cnt2[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    sieve(N);
    for (int i = 1; i < N; ++i) {
        cnt1[i] = cnt1[i - 1] + (C[i] == i);
        cnt2[i] = cnt2[i - 1] + is_palin(i);
    }
    int ans = 0;
    LL p, q;
    cin >> p >> q;
    for (int i = 1; i < N; ++i) {
        if (q * cnt1[i] <= p * cnt2[i]) ans = i;
    }
    cout << ans << '\n';
    return 0;
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef unsigned int uint;
typedef long long int llint;

const int N = 10000000;
bool prime[N];
int nprimes[N];
int npals[N];

bool ispal(int n) {
    int m = 0, k = n;
    while (n > 0){
        m *= 10;
        m += n % 10;
        n /= 10;
    }
    return m == k;
}

int main() {
    ios_base::sync_with_stdio(false);
    llint p, q;
    cin >> p >> q;
    // erato
    for (llint i = 2; i < N; i++) {
        prime[i] = true;
    }
    for (llint i = 2; i < N; i++) {
        if (prime[i]) {
            for (llint j = i * 2; j < N; j+=i){
                prime[j] = false;
            }
        }
        nprimes[i] = nprimes[i-1] + prime[i];
    }
    for (llint i = 1; i < N; i++ ){
        npals[i] = npals[i-1] + ispal(i);
    }
    for (llint n = N; n >= 1; n--){
        if (npals[n] * p >= nprimes[n] * q) {
            cout << n << endl;
            return 0;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

inline bool palindrome(const ll& x) {
    ll t1 = x, t2 = 0;
    while (t1) {
        t2 = t2 * 10 + (t1 % 10);
        t1 /= 10;
    }
    return x == t2;
}

bool prime[(ll)1e7 + 5];

int main() {
    ll cnt1 = 0, cnt2 = 0, res = 0, p, q;
    cin >> p >> q;
    for (ll i = 2; i <= 1e7; i++) prime[i] = 1;
    for (ll i = 2; i <= 5e6; i++)
        if (prime[i])
            for (ll j = i << 1; j <= 1e7; j += i)
                prime[j] = false;
    for (ll i = 1; i <= 1e7; i++) {
        cnt1 += palindrome(i);
        cnt2 += prime[i];
        if (q * cnt2 <= p * cnt1) res = i;
    }
    return cout << res, 0;
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

const int M = 2000000;
int t[M + 7];
int pi[M + 7];
int rub[M + 7];

bool palin(int n) {
	int x = n;
	int y = 0;
	while(n > 0) {
		y *= 10;
		y += n % 10;
		n /= 10;
	}
	return x == y;
}

int main() {
	ios_base::sync_with_stdio(0);
	for(int i = 2; i * i <= M; ++i) {
		if(!t[i]) for(int j = i + i; j <= M; j += i) t[j] = i;
	}
	for(int i = 2; i <= M; ++i) if(!t[i]) t[i] = i;
	rub[1] = 1;
	for(int i = 2; i <= M; ++i) {
		pi[i] = pi[i - 1];
		if(t[i] == i) pi[i]++;
		rub[i] = rub[i - 1];
		if(palin(i)) rub[i]++;
	}

	int a, b;
	cin >> a >> b;
	int w = -1;
	for(int i = M; i >= 1; --i) {
		if(b * pi[i] <= a * rub[i]) {
			w = i;
			break;
		}
	}
	if(w == -1) cout << "Palindromic tree is better than splay tree";
	else cout << w << endl;
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define N 1300000
bool isprime[N+2];
long long sump[N+2];
long long sumr[N+2];
bool isrub[N+2];
long long s[105];
bool pd(long long x)
{
    long long len=0;
    while(x)
    {
        s[len++]=x%10;
        x/=10;
    }
    for(long long i=0;i<len;i++)
    {
        if(s[i]!=s[len-1-i])
            return false;
    }
    return true;
}
int main()
{
    //isprime[1]=1;
    for(long long i=2;i<=N;i++)
    {
        if(!isprime[i])
        for(long long j=i*i;j<=N;j+=i) isprime[j]=1;
    }
    for(long long i=2;i<=N;i++) isrub[i]=pd(i);
    sumr[1]=1;
    for(long long i=2;i<=N;i++)
    {
        sump[i]=sump[i-1]+!isprime[i];
        sumr[i]=sumr[i-1]+isrub[i];
    }
    //cout<<sump[N]/sumr[N]<<endl;
    long long p,q;
    scanf("%I64d%I64d",&p,&q);
    long long maxn=-1;
    for(long long i=1;i<=N;i++)
    {
        if(q*sump[i]<=p*sumr[i])
            maxn=i;
    }
    if(maxn!=-1)
    cout<<maxn<<endl;
    else printf("Palindromic tree is better than splay tree\n");
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fore(i,n) for(int i = 0; i< n ; i++ )
#define lop(i,n) for(int i = 1 ; i<=n ; i++ )
#define ops(i,n) for(int  i = n-1 ; i>=0 ; i-- )
#define forall( it,g )  for( typeof(g.begin()) it=g.begin();it!=g.end();it++ )
#define PI  3.141592653589793
#define mod  1000000007
#define inf 1000000000
#define INF -200000300
#define modulo 1073741824
#define MH 1234533333333337
#define MH2 7779845079489377
#define enter endl
//ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
using namespace std;
typedef vector <int> vi;
typedef vector <vector <int> > vv;
typedef vector <pair <int,int > >vp;
typedef vector <vector <pair <int ,int > > > vvp;
typedef vector <pair <int ,pair <int ,int > > > vpp;
typedef pair<int,int> pp;
typedef long long ll;
typedef unsigned long long ull;
int n=5000001;
bool prime[5000001];
int pre[5000001],prep[5000001];
bool pal(int x){
  string s = "";
  while(x){
    s+=x%10 + '0';
    x/=10;
  }
  fore(i , s.size()/2){
    if(s[i]!=s[s.size()-i-1])
      return false;
  }
  return true;
}
void solve(){
    fill_n(prime,sizeof prime,true);
    prime[0] = false;
    prime[1] = false;
    for(int i = 2;i*i<=n;i++){
        if(prime[i]){
            for(int j = i*i;j<=n;j+=i){
                prime[j]=false;
            }
        }
    }
    lop(i , n){
      prep[i] = prep[i-1] + pal(i);
      pre[i] = pre[i-1]+ prime[i];
    }
}
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  solve();
  double p,q;
  cin >> p >> q;
  double A = p/q;
  int ans = -1;
  lop(i , n){
    if(A >= (1.0 * pre[i])/(1.0 * prep[i])){
      ans = i;
    }
  }
  if(ans == -1){
    cout << "Palindromic tree is better than splay tree" <<enter;
  }else cout << ans << enter;
  return 0;
}

//By UditDesai
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define trav(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define nl cout<<'\n'
#define sp <<' '<<
#define sz(a) (int)(a.size())
#define check(x) cout << #x << " : " << (x) << endl
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl//By UditDesai
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int N=1e7+2,MOD=1e9+7;
const ld EPS = 1e-9;
bool prime[N];
bool palin[N];
bool ispalin(int a)
{
	int rev = 0;
	int tmp = a;
	while(tmp)
	{
		rev  = rev * 10 + tmp%10;
		tmp/=10;
	}
	if(rev==a) return true;
	else return false;
}
int main()
{
	fastio;
	ll i,j;
	forn(i,N) prime[i] = true;
	prime[1] = prime[0] =  false;
 	palin[1] = palin[0] = true;
 	for(i=2;i<N;i++)
	{
		if(ispalin(i)) palin[i] = true;
		if(prime[i])
		{
			for(j=i*i;j<N;j+=i) prime[j] = false;
		}
	}
	ll p,q;cin>>p>>q;
	ll ans = -1;
	int pi[N]={};
	int rub[N]={};
	for(i=1;i<N;i++)
	{
		pi[i] = pi[i-1] + (prime[i]?1:0);
		rub[i] = rub[i-1] + (palin[i]?1:0);
		//cout<<i sp pi[i] sp rub[i];nl;
		if(q*pi[i]<=p*rub[i]) ans = max(ans,i);
	}
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll P,q;
ll a[10000005],p[10000005];
bool prime[10000005];
ll rev(ll x)
{
	ll an=0;
	while(x)
	{
		an=an*10+x%10;
		x/=10;
	}
	return an;
}
int main() {
slld(P);slld(q);

for(int i=1;i<=9999999;i++)
	if(rev(i)==i)
		a[i]++;
for(int i=1;i<=10000000;i++)
	a[i]+=a[i-1];
memset(prime,1,sizeof prime);
prime[0]=false;
prime[1]=false;
for(int i=2;i<=20000;i++)
{
	if(prime[i])
	{
		p[i]++;
		for(int j=i*i;j<=10000000;j+=i)
			prime[j]=0;
	}
}
for(int i=20001;i<=10000000;i++)
if(prime[i])p[i]++;
for(int i=1;i<=10000000;i++)
	p[i]+=p[i-1];
for(int i=10000000;i>=1;i--)
{
	if(q*p[i]<=P*a[i])
	{
		pd(i);
		return 0;
	}
}
pss("Palindromic tree is better than splay tree\n");
	return 0;
           }

#pragma comment (linker,"/STACK:256000000")
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <cassert>
#include <string>
#include <time.h>
#include <stdlib.h>
using namespace std;

#define INF 1000000000
#define lint long long
#define pb push_back
#define MOD 1000000007
#define mp make_pair

char prime[25000005];
int pr[25000005];
int pl[25000005];

int ispal(int num)
{
	int b[10], k = 0;
	while(num)
	{
		b[k++] = num % 10;
		num /= 10;
	}

	for(int i = 0; i < k; ++i)
	{
		if(b[i] != b[k - 1 - i])
			return 0;
	}
	return 1;
}
int main()
{
	int i, j;
	for(i = 2; i <= 5000; ++i)
	{
		if(prime[i]) continue;
		for(j = i + i; j <= 25000000; j += i)
		{
			prime[j] = 1;
		}
	}

	pr[1] = 0;
	for(i = 2; i <= 25000000; ++i)
	{
		pr[i] = pr[i - 1] + (prime[i] == 0);
	}

	for(i = 1; i <= 25000000; ++i)
	{
		pl[i] = pl[i - 1] + ispal(i);
	}

	int p, q;
	int ans = 1;
	cin >> p >> q;
	for(i = 1; i <= 25000000; ++i)
	{
		if(q*1ll*pr[i] <= p*1ll*pl[i])
		{
			ans = i;
		}
	}
	cout << ans << endl;

	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 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<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
const int MAX_N = 10000000;

bool P[MAX_N];
int Pn;

void prime_init(){
    P[0] = 1;
    P[1] = 1;
    int a= 0;
    for (int i = 2; i < MAX_N; i++) {
        if (P[i]) continue;
    //  if (i>MAX_N - 10086) cout<<i-a<<' ';
        for (int k = i + i; k < MAX_N; k += i) {
            P[k] = true;
        }
    //  a = i;
    }
}

int ok(int x){
    int p = 1;
    for (;p < x; p*=10) ;
    p/=10;
    for (;x>=10;){
        int a = x % 10;
        int b = x / p;
        if (a != b) return 0;
        x -= b * p;
        x /= 10;
        p /= 100;
    }
    if (x==0) return 1;
    if (p>1) return 0;
    return 1;
}

int main(){
    int ans = 0;
    long long tot1 = 0, tot2 = 0, p, q;
    prime_init();
    cin>>p>>q;
    for (int i = 1; i < MAX_N; i++) {
        if (!P[i]) {
            ++tot1;
        }
        if (ok(i)) {
            ++tot2;
        //  cout<<i<<endl;
        }
        if (tot1 * q <= tot2 * p) {
        //  cout<<tot1<<endl;;
            ans = i;
        }
    }
    if (ans < MAX_N/2) cout<<ans<<endl;
    else puts("Palindromic tree is better than splay tree");
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <float.h>

using namespace std;

int isPoly(int index){
    bool result = true;
    int k = index, j = 0;
    while (k > 0){
        j *= 10;
        j += k % 10;
        k /= 10;
    }
    return j == index;
}

int main() {
    const int maxn = 2e6;
    vector<int> d(maxn, -1);
    vector<int> p;

    for (int i = 2; i < maxn; i++){
        if (d[i] == -1){
            d[i] = i;
            p.push_back(i);
        }
        for (int j = 0; j < p.size(); j++){
            //if (d[i] != i) continue;
            if (p[j] * i >= maxn) break;
            d[p[j]*i] = p[j];
        }
    }

    vector<int> pi(maxn, 0), rub(maxn, 0);

    for (int i = 1; i < maxn; i++){
        rub[i] = rub[i - 1] + isPoly(i);
        pi[i] = pi[i - 1] + (d[i] == i);
    }

    int mxrub = rub[maxn - 1];
    int mxpi = pi[maxn - 1];

    int pp, qq, n = 1;
    cin >> pp >> qq;

    for (int i = 1; i < maxn; i++){
        if (qq * pi[i] <= pp * rub[i]) n = i;
    }

    cout << n;

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <map>
#define modulus 1000000007
#define ll long long
using namespace std;

const int MAXN = 1e7 + 1;

vector<bool> prime(MAXN, true);
vector<int> arr(MAXN, 0), brr(MAXN, 0);

bool ispallin(int n){
    string str = to_string(n);
    int i = 0, j = str.size() - 1;
    while(i < j){
        if(str[i] == str[j]){
            i++;
            j--;
        }
        else return false;
    }
    return true;
}

void f(){
    brr[0] = 0;
    for(int i = 1; i < MAXN; i++){
        brr[i] = brr[i - 1];
        if(ispallin(i)) brr[i]++;
    }
}

void SieveOfEratosthenes(int n){
    for(int p=2; p*p<=n; p++){
        if (prime[p] == true){
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    arr[0] = arr[1] = 0;
    arr[2] = 1;
    for(int i = 3; i < MAXN; i++){
        arr[i] = arr[i - 1];
        if(prime[i]) arr[i]++;
    }
}

int main(){
    SieveOfEratosthenes(MAXN);
    f();
    // for(int i = 0; i < 20; i++) cout << arr[i] << " ";
    // cout << endl;
    // for(int i = 0; i < 20; i++) cout << brr[i] << " ";
    // cout << endl;
    ll p, q;
    cin >> p >> q;
    int maxi = -1;
    for(int i = 1; i < MAXN; i++){
        if((ll)arr[i] * q <= (ll)brr[i] * p){
            maxi = i;
        }
        // else break;
    }
    if(maxi == -1) cout << "Palindromic tree is better than splay tree" << endl;
    else cout << maxi << endl;
}

#include <bits/stdc++.h>
using namespace std;

const int OO = 0x3f3f3f3f ,N = 1e7+5 ,mod = 1e9+9 ;
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define BeatMeIFUCAN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int cprime[N] ,cplndrm[N] ,p ,q ,ans=-1 ;
bool f[N] ,plnd[N] ;
vector<int> prime ,pl;
void sieve(){
    f[0]=f[1]=1;
    for(int i=2;i<N;++i){
        if(f[i])continue;
        for(int j=i*i;i<=10000&&j<N;j+=i) f[j]=1 ;
    }
}
void gt(){
    int tmp=0 ;
    for(int i=0;i<pl.size();++i)tmp=tmp*10+pl[i];
    for(int i=pl.size()-2;i>=0;--i) tmp=tmp*10+pl[i];
    if(tmp<N) plnd[tmp]=1;
    tmp=0;
    for(int i=0;i<pl.size();++i)tmp=tmp*10+pl[i];
    for(int i=pl.size()-1;i>=0;--i) tmp=tmp*10+pl[i];
    if(tmp<N) plnd[tmp]=1;
}
void plndrome(){
    if(pl.size()>4) return ;
    gt();
    for(int i=0;i<10;++i){
        if(!i&&!pl.size()) continue ;
        pl.push_back(i);
        plndrome();
        pl.pop_back();
    }
}
int main(){
    cin>>p>>q;
    sieve();
    for(int i=1;i<N;++i) cprime[i]=1-f[i]+cprime[i-1];
    plndrome();
    for(int i=1;i<N;++i) cplndrm[i]=plnd[i]+cplndrm[i-1];
    for(int i=1;i<N;++i){
        if(cprime[i]<=1ll*p*cplndrm[i]/q) ans=i;
    }
    if(ans==-1) puts("Palindromic tree is better than splay tree");
    else cout<<ans;
    return 0 ;
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdlib>

#define sz(c) (int)c.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LL long long
#define mod (int)1e9+7

using namespace std;

int a[123], k;

bool isPal(int n) {
    k = 0;
    //memset(a, 0, sizeof(a));
    int x = n;
    while(x > 0) {
        a[k] = x % 10;
        k++;
        x /= 10;
    }
    int y = 0;
    for(int i = 0; i < k; i++)  {
        y *= 10;
        y += a[i];
    }
    return (y == n);
}

int p, q;
int pr[1234568], rub[1234568];
int cur_pal = 0, cur_pr = 0, n = 1234567;

int main() {

    //freopen("input.txt", "r", stdin);

    cin >> p >> q;

    vector<char> prime (n+1, true);
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; ++i)
      if (prime[i])
        if (i * 1ll * i <= n)
            for (int j=i*i; j<=n; j+=i)
                prime[j] = false;

    for(int i = 1; i <= n; i++) {
        if(isPal(i))
            cur_pal++;
        rub[i] = cur_pal;
    }

    for(int i = 1; i <= n; i++) {
        if(prime[i])
            cur_pr++;
        pr[i] = cur_pr;
    }

    for(int i = n; i >= 1; i--) {
        if( 1LL * q * pr[i] <=  1LL * p * rub[i]) {
            cout << i << endl;
            return 0;
        }
    }

    cout << "Palindromic tree is better than splay tree" << endl;

    return 0;
}

#include<bits/stdc++.h>
#define up(j,k,i) for(i=j;i<k;i++)
#define down(j,k,i) for(i=j;i>k;i--)
#define pp(n) printf("%lld\n",n)
#define is(n) scanf("%lld",&n)
#define ss(s) scanf("%s",s)
#define cool 0
typedef int l;
typedef float f;
typedef double d;
typedef long long int lld;
using namespace std;
const lld M = 2e6;
bool sprime [M];
lld prime[1000000],total_prime,total[M],rub[M];
lld dif_max=0;
lld p,q;
/*
2999

*/
void sieve()
{
	sprime[2]=0;
	sprime[1]=1;
	lld i,temp;
	for(i=1;i<M;i++)
	{
	    total[i]=total[i-1];

		if(sprime[i]==0)
		{
		    total[i]++;
		    temp=i;
			lld j;
			for(j=i*i;j<M;j+=i)
				sprime[j]=1;
			prime[total_prime]=i;
			total_prime++;
		}
	}
//	cout<<total_prime<<endl;
}
lld check(lld n)
{
    lld digits=0,p10=1,t1,t2;
    while(p10<=n)
    {
        p10*=10;
        digits++;
    }
    digits--;
    p10/=10;
    while(n)
    {
     t1=n/p10;
     t2=n%10;

        if(t1!=t2)
        return 0;
        n-=t1*p10;
        n/=10;
        p10/=100;
    }
    return 1;
}
lld fcal(lld i)
{
    lld ans=q*total[i];
    ans-=(p*rub[i]);
 //   cout<<rub(i)<<endl;
    return ans;
}
void pre_comp()
{
lld i;
rub[0]=0;
    up(1,M,i)
    {
        rub[i]=rub[i-1];
        if(check(i))
            rub[i]++;
    }
}
int main()
{

    pre_comp();
    sieve();
    is(p);
    is(q);
    lld i=0,j=0;
     lld f=M-100;
    while(f>=1)
    {
        if(fcal(f)<=0)
        {
            break;
        }
        f--;
    }
    if(fcal(f)<=0&&f>=1)
    pp(f);
    else
    printf("Palindromic tree is better than splay tree\n");
    return 0;
}

/*input
1000 1000
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=3e6+5;
const ll maxlg=__lg(maxn)+2;
ll pref[maxn],pref2[maxn];
bool isp[maxn];
bool pal(int x){
    string s=to_string(x);
    string z=s;
    reverse(ALL(z));
    return (z==s);
}
void sieve(){
    for(int i=2;i<maxn;i++){
        if(!isp[i]){
            pref[i]=pref[i-1]+1;
            for(int j=i*2;j<maxn;j+=i) isp[j]=1;
        }
        else pref[i]=pref[i-1];
    }
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    ll a,b;
    cin>>a>>b;
    int g=__gcd(a,b);
    a/=g;
    b/=g;
    sieve();
    REP1(i,maxn-1){
        pref2[i]=pref2[i-1]+pal(i);
    }
    for(int i=maxn-1;i>=0;i--){
        //cout<<pref2[i]<<' '<<pref[i]<<'\n';
        if(a*pref2[i]>=b*pref[i]){
            cout<<i<<'\n';
            return 0;
        }
    }
    assert(false);
}

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5e6 + 10;

int n, p, q;

vector<int> primes;
vector<int> palindromes;

int cnt_primes[N], cnt_palin[N];
vector<bool> Prime(N+10, 1);
vector<bool> Palindrome(N+10, 1);

void sieve(int N) {
   #define int long long
   Prime[0] = Prime[1] = false;
   for(int i = 2; i <= N; ++i) {
      if(Prime[i]) {
         // Mark all the multiples of i as composite numbers
         for(int j = i * i; j <= N ;j += i)
            Prime[j] = false;
      }
   }
   //Prime[i] = true, means that i is prime
   #undef int
}

bool is_palindrome(int x){
   string s = to_string(x);

   for (int i = 0, j = sz(s)-1; i <= j; ++i, --j)
   {
      if(s[i] != s[j])
         return 0;
   }

   return 1;
}

int32_t main(){_

   cin >> p >> q;

   sieve(N);

   Palindrome.resize(N);

   for (int i = 1; i < N; ++i)
   {
      Palindrome[i] = 0;
      Palindrome[i] = is_palindrome(i);

      cnt_primes[i] = cnt_primes[i-1];
      cnt_primes[i] += Prime[i];

      cnt_palin[i] = cnt_palin[i-1];
      cnt_palin[i] += Palindrome[i];
   }

   int ans = -1;
   for (int i = N-1; i >= 1; --i)
   {
      if (q * cnt_primes[i] <= p * cnt_palin[i]){
         ans = i;
         cout<<ans;
         exit(0);
      }
   }

   cout<<"Palindromic tree is better than splay tree";

   return 0;
}

//

//  main.cpp

//  coding is back

//

//  Created by VERDU SANJAY on 23/01/17.

//  Copyright © 2017 VERDU SANJAY. All rights reserved.

//

#include <iostream>
#include<string.h>
#include<map>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stack>
#include<time.h>
#include<fstream>
#define mod 1000000007

using namespace std;

typedef long long ll;

using namespace std;

map<string,string> mp;

ll prime(ll n ){

    ll i;

    if(n<2)
        return 0;
    else{

        for(i=2;i*i<=n;i++){

            if(n%i==0)
                return 0;

        }
        return 1;
    }

}

ll palin(ll no){

    ll temp = 0;
    ll a;
    ll b = no;

    while(no>0)
    {
        a=no%10;
        no=no/10;
        temp=temp*10+a;
    }

    if(temp == b)
        return 1;
    else
        return 0;

}

int main(){

    double p,q;

    cin>>p>>q;

    ll i;
    ll ans1 = 0;
    ll primes = 0;

    ll palindromes = 0;

    for(i=1;i<=1000000;i++){

        ll k = prime(i);

        if(k==1)
            primes++;

        ll k1 = palin(i);

        if(k1==1)
            palindromes++;

        double f = p/q;

        double ans = ((double)primes/(f*palindromes));

        if(ans<=1)
        {
            ans1 = max(ans1,i);

        }

    }

    if(ans1!=0)
    {
        cout << ans1<<endl;return 0;
    }

    cout << "Palindromic tree is better than splay tree";

    return 0;

}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 3e5 + 100;
int prime[MAXN];
int gPrime[MAXN];
int sum[MAXN];

int p, q;

bool judge(int num)
{
	string tmp = "";
	if(num == 0)
		return true;
	while(num)
	{
		tmp += num % 10 + '0';
		num /= 10;
	}
	for(int i = 0, len = tmp.size(); i < len / 2; i++)
	{
		if(tmp[i] != tmp[len - i - 1])
		{
			return false;
		}
	}
	return true;
}

void getPrime(int n)
{
	memset(prime, 0, sizeof prime);
	sum[0] = 0;
	sum[1] = 1;
	gPrime[0] = 0;
	gPrime[1] = 0;
	for(int i = 2; i <= n; i++)
	{
		if(!prime[i])
			prime[++prime[0]] = i;
		for(int j = 1; j <= prime[0] && prime[j] <= n / i; j++)
		{
			prime[i * prime[j]] = 1;
			if(prime[j] % i == 0)
			{
				prime[i] = 0;
				break;
			}
		}
		gPrime[i] = prime[0];
		if(judge(i))
			sum[i] = sum[i - 1] + 1;
		else
			sum[i] = sum[i - 1];
	}
}

bool check(int x)
{
	if(p * sum[x] >= gPrime[x] * q)
		return true;
	else
		return false;
}

int main()
{
	getPrime(210000);
	while(~scanf("%d %d", &p, &q))
	{
		int n = -1;
		for(int i = 1; i <= 210000; i++)
		{
			if(check(i))
				n = i;
		}
		cout << n << endl;
	}
	return 0;
}

#pragma comment(linker, "/stack:32000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <functional>
#include <stack>
#include <cstring>
#include <locale>
#include <cstdio>

using namespace std;

#define ll long long
#define ull unsigned ll
#define mp(a,b) (make_pair(a,b))
#define vv(a, n, m, v) vector<vector<a>> v(n, vector<a>(m))

#define Y first
#define X second
#define lendl cout<<endl
#define INF (ll)1e18
#define PR (ll)1000003
#define OST (ll)1000003
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double, double>
#define EPS (double)1e-9
#define PI (double)3.1415926535897
#define vi vector<int>
#define vii vector< vi >
#define vl vector<ll>
#define vll vector< vl >
#define vc vector<char>
#define vs vector<string>
int n, m, k;

//void ToLower(string& s) {
//	for (int i = 0; i < s.length();) {
//		if (!(s[i] >= -1 && s[i] <= 255) || !isalpha(s[i]))
//			s.erase(s.begin() + i);
//		else i++;
//	}
//
//	for (int i = 0; i < s.length(); i++) {
//		s[i] = tolower(s[i]);
//	}
//}
//string ToString(int val) {
//	string res = "";
//	while (val > 0) {
//		res += (val % 10) + '0';
//		val /= 10;
//	}
//	reverse(res.begin(), res.end());
//	return res;
//}

vii gr;

ll ar[100001];
ll artemka(ll m_cnt, int n) {
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += max(m_cnt - ar[i], (ll)0);
	}
	return ans;
}
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//string _file_name_ = "repair";
	//freopen((_file_name_ + ".in").c_str(), "r", stdin); freopen((_file_name_ + ".out").c_str(), "w", stdout);
#endif
	int top = 1e7;
	int p ,q;
	cin >> p >> q;
	 //1e8 = 1500 ctr  5761455

	vector<char> prime(top + 1, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= top; ++i)
		if (prime[i])
			if (i * 1ll * i <= top)
				for (int j = i*i; j <= top; j += i)
					prime[j] = false;

	int cnt = 0;
	for (int i = 2; i <= top; ++i) {
			cnt += prime[i];
	}

	int cnt2 = 0;
	for (int len = 1; len <= 9; len++) {
		int t_cnt = 0;
		if (len % 2 == 1) {
			t_cnt = 10;
			for (int jj = 1; jj < len / 2; jj++)
				t_cnt *= 10;
			t_cnt *= 9;
		}
		else {
			for (int jj = 1; jj < len / 2; jj++)
				t_cnt *= 10;
			t_cnt *= 9;
		}
		if (len == 1)
			t_cnt = 9;
		cnt2 += t_cnt;
	}
	cout << cnt << " vs " << cnt2 << endl;

	ll _cnt1 = cnt;
	ll _cnt2 = 0;
	int ans = 0;
	for (int i = top; i > 0; i--) {
		_cnt2 = 0;
		int cop = i;
		int _len = 0;
		while (cop) {
			cop /= 10;
			_len++;
		}
		for (int len = 1; len < _len; len++) {
			int t_cnt = 1;
			for (int jj = 1; jj < len / 2; jj++)
				t_cnt *= 10;
			t_cnt *= 9;
			if (len % 2 == 1)
				t_cnt *= 10;
			if (len == 1)
				t_cnt = 9;

			_cnt2 += t_cnt;
		}

		int t_cnt = 1;
		for (int jj = 1; jj < _len / 2; jj++)
			t_cnt *= 10;
		t_cnt *= 9;
		if (_len % 2 == 1)
			t_cnt *= 10;
		if (_len == 1)
			t_cnt = 9;
		_cnt2 += t_cnt;

		cop = i;
		int divider = 1;
		for (int j = 0; j < _len / 2; j++)
			divider *= 10;
		cop = cop % divider;
		_cnt2 -= cop / 10 + 1;

		if (_cnt1 * p <= _cnt2 * q) {
			ans = i;
			break;
		}

		_cnt1 -= prime[i];
	}
	cout << ans;
	return 0;
}

#include <iostream>
#include "math.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

bool isPalindrome(long long n){
	string str_int = "";
    while(n){
        str_int.push_back('0' +n%10);
        n = n/10;
    }
	long long length = str_int.length();
	int i = 0;
	while(i < length/2){
		if(str_int[i] != str_int[length-i-1]){
			return false;
		}
		i++;}
	return true;

}

int main(){
    int p;
    int q;
    cin>>p;
    cin>>q;
    int Iter = 2005;
	bool prime_array [Iter];
    int count_prime = 0;
    int count_palindrome = 1;
    int optimal_n= 1;
    memset(prime_array, 0, sizeof(prime_array));
    int i = 2;
    int k;
    while(i<Iter){
        if(prime_array[i]== 0){
        	count_prime = count_prime + 1;
            k = i*i;
            while(k<Iter){
                prime_array[k] = 1;
                k = k+i;
            }
        }

        if(isPalindrome(i) == 1)
        	count_palindrome = count_palindrome +1;
        if(q*count_prime <= p*count_palindrome)
            optimal_n = i;
        i++;
    }

    cout<<optimal_n<<endl;
}

#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<cmath>

typedef unsigned long long ulol;
typedef long long lol;

using namespace std;

bool isPrime(lol n) {
    if ( n == 2 ) {
        return true;
    }

    for ( lol i = 2; i <= lol(sqrt(n))+1; i++) {
        if ( n%i == 0 ) {
            return false;
        }
    }
    // cout <<"prime "<<n<<endl;
    return true;
}

bool isPalind(lol n) {
    lol reverse = 0;
    lol old = n;
    while(n) {
        reverse = reverse*10+n%10;
        n /= 10;
    }
    // if ( old == reverse ) {
    //     cout<<"palind !!! "<<old<<endl;
    // }
    return old == reverse;
}

void solve(lol p,lol q) {
    lol find = true;
    lol next = 1;
    lol prime = 0;
    lol palind = 0;
    lol ans = 0;
    while (next < 1000000) {
        prime += (next!=1) && isPrime(next);
        palind += isPalind(next);
        // cout << "prime "<<prime <<" palind "<<palind<<endl;
        if ( q*prime <= p*palind) {
            // cout <<next<<"!!"<<prime<<" "<<palind<<endl;
            ans = next;
        }
        next += 1;
        // cout << next<<" "<<prime<<" "<<palind <<endl;
    }
    if ( ans == 0 ) {
        cout<<"Palindromic tree is better than splay tree\n";
    } else {
        cout<<ans<<endl;
    }
    getchar();
}

int main () {
    lol p,q;
    cin >>p>>q;
    solve(p,q);
    return 0;
    // for (int i = 0; i < 9999; i++) {
    //     cout << i<<" "<< isPalind(i)<<endl;
    // }
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll OO =(ll)1e15;

vector <ll> v1;
map<char,ll>ma;
int pal[10000000];
int pri[10000000];

void sieve(ll n)
{
   int i,c=0,j;
    pri[0]=1,pri[1]=1;
     for (int i = 2; i * i <= n; i++)
        {
        if (!pri[i])
          {
            for (int j = i * i; j <= n; j += i)
            {
              pri[j] = true;
            }
          }
        }

}

ll f(ll n)
{
    int c=0;
    for(int i=1;i<=n;i++)
    {
      string s,x;
      stringstream ss;
      ss << i;
      s = ss.str();
      x=s;
      reverse(s.begin(), s.end());
      if(x==s)
      {
          pal[i]=1;
      }
    }

}

int main()
{
    ll p,q,pr=0,pa=0,t=0;
    cin>>p>>q;
    sieve(1000000);
    f(1000000);

    for (ll i = 1; i <= 1000000; i++)
    {
		if (pri[i]==0)
		 {
		     pr++;
		 }
		if (pal[i]==1)
		 {
		     pa++;
		 }
		if (pa * p >= pr * q)
		 {
		     t = i;
		 }
	}
 if(t!=0)
  cout<<t;
  else
    cout<<"Palindromic tree is better than splay tree";
}

#include <bits/stdc++.h>

using namespace std;
const int N = 1e8;
typedef long long ll;
bool ispri[N];
bool ispal[N];
void spal() {
    for (int i = 1; i < N; i++) {
        int j; j = i; int s = 0;
        int a[10];
        while (j) {
            a[s++] = j % 10;
            j /= 10;
        }
        bool ok = true;
        for (int i = 0; i < s / 2; i++) {
            if (a[i] != a[s - i - 1]) {
                ok = false;
            }
        }
        if (ok) {
            ispal[i] = 1;
        }
    }
}
void spri() {
    ispri[1] = 0;
    for (ll i = 2; i < N; i++) {
        if (ispri[i]) {
            for (ll j = i; j * i < N; j++) {
                ispri[j * i] = 0;
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for (int i = 1; i < N; i++) ispri[i] = 1;
    spal();
    spri();
    int pa = 0;
    int pr = 0;
    int p, q; cin >> p >> q;
    int ans;
    for (int i = 1; i < N; i++) {
        if (ispal[i]) {
            pa += p;
        }
        if (ispri[i]) {
            pr += q;
        }
        if (pa >= pr) {
            ans = i;
        }
    }
    cout << ans;
    return 0;
}

#include <vector>
#include <stdio.h>
#include <string.h>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
typedef long long ll;
typedef double d;
using namespace std;
//int direcy[]= {1,-1,0},direcx[]= {0,0,1};
bool arr[1200006];
bool ch(ll x)
{
    stringstream ss;
    string s;
    ss<<x;
    ss>>s;
    for(int i=0;i<=s.size()/2;i++)
        if(s[i]!=s[s.size()-1-i])
        return 0;
        return 1;
}
int main()
{
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    for(int i =0; i<1200006; i++)
        arr[i]=1;
    arr[0]=0;
    arr[1]=0;
    for(ll i =2; i<=1200006; i++)
    {
        if(arr[i])
            {
                for(ll j=i*i; j<=1200006; j+=i)
                arr[j]=0;
            }
    }
    int out=-1,conprime=0,conplant=0;
    d a,p;
    cin >> a>>p;
    a=a/p;
    for(int i =1;i<1200006;i++)
    {
        if(ch(i))
        conplant++;
        if(arr[i])
        conprime++;
        if((d)conprime<=(d)a*conplant)
            {
                out=max(out,i);
            }
    }
    if(out==-1)
    cout << "Palindromic tree is better than splay tree"<<endl;
    else
    cout << out << endl;
    return 0;
}

#include<bits/stdc++.h>

#define ll long long
#define ld double
#define sf(x) sort(x.begin(),x.end(),func);
#define s(x) sort(x.begin(),x.end())
#define pb push_back
#define set(v, val) memset(v, val, sizeof(v));
#define rs(v) { s(v) ; r(v) ; }
#define all(v) v.begin(),v.end()
#define r(v) { reverse(all(v)) ; }
#define mod 1000000007
#define inf LONG_MAX
#define ninf LONG_MIN
#define mp make_pair
#define F first
#define S second
using namespace std;
ll is[500005];
double cp[500005];
double pp[500005];
ll check(ll n)
{
    vector < ll > v;
    while(n)
    {
        v.pb(n%10);
        n /= 10;
    }
    ll j = v.size()-1;
    for(ll i=0;i<v.size()/2;i++)
    {
        if(v[i]!=v[j])
        {
            return 0;
        }
        j--;
    }
    return 1;
}
int main()
{
    ll c = 0;
    cp[1]=0;
    double p,q;
    cin>>p>>q;
    for(ll i=2;i<500005;i++)
    {
        if(is[i]==0)
        {
            c++;
            for(ll j=i*i;j<500005;j+=i)
            {
                is[j]=1;
            }
        }
        cp[i]=c;
    }
    c = 0;
    for(ll i=1;i<500005;i++)
    {
        if(check(i))
        {
            c++;
        }
        pp[i]=c;
    }
    double d = p/q;
    for(ll i=500004;i>=0;i--)
    {
        if(cp[i]<=pp[i]*d)
        {
            cout<<i<<"\n";
            return 0;
        }
    }
    cout<<"Palindromic tree is better than splay tree\n";
    return 0;
}

#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i , j ;
bool isprime(int n)
{
	if ( n == 2 || n == 3 )
	{
		return true;
	}
	if ( n == 1|| n % 2 == 0 || n % 3 == 0 )
	{
		return false;
	}
	for ( int i = 5,t=2;i*i <= n ; i+=t,t=6-t )
	{
		if ( n % i == 0 )
		{
			return false;
		}
	}
	return true;
}
int pr[10000005],r[10000005];
int main()
{
	for ( i = 1; i <= 10000000 ;i++ )
	{
		r[i] = r[i-1];
		pr[i] = pr[i-1];
		int k = i;
		string s = "";
		while ( k )
		{
			s += k%10+'0';
			k/=10;
		}
		for ( j = 0 ; j < s.size()+1 ; j++ )
		{
			if ( s[j] != s[s.size()-j-1] )
			{
				break;
			}
		}
		if ( j == s.size()+1 )
		{
			r[i]++;
		}
		if ( isprime(i) )
		{
			pr[i]++;
		}
	}
	int p,q;
	cin >> p >> q;
	for ( i = 10000000 ; i >= 1 ; i-- )
	{
		if ( pr[i] * q <= p*r[i] )
		{
			cout << i << endl;
			return 0;
		}
	}
}

#include <bits/stdc++.h>
#define MAX 10000005
using namespace std;
typedef long long ll;

long long p, q, d, pi[MAX], rub[MAX];

void crivo () {
    for (long long i = 2; i < MAX; i++) {
        if (!pi[i]) {
            for (long long j = i*i; j < MAX; j += i)
                pi[j] = 1;
        }
    }
}

void palindromo () {
    rub[0] = 0;
    for (int i = 1; i < MAX; i++) {
        char num[10];
        long long k = 0, aux = i;
        while (aux > 0) {
            num[k++] = (aux%10) + '0';
            aux /= 10;
        }
        num[k] = '\0';
        bool f = true;
        if (num[0] != '0') {
            for (int j = 0; j < k / 2; j++) {
                if (num[j] != num[k - 1 - j])
                    f = false;
            }
        } else {
            f = false;
        }
        if (f)
            rub[i] = rub[i-1] + 1;
        else
            rub[i] = rub[i-1];
    }
}

long long mdc (long long a, long long b) {
    if (b == 0) return a;
    return mdc (b, a % b);
}

int main () {
    for (int i = 0; i < MAX; i++)
        pi[i] = 0;

    crivo ();

    for (int i = 2; i < MAX; i++) {
       if (pi[i] == 0)
          pi[i] = pi[i-1] + 1;
       else
          pi[i] = pi[i-1];
    }

    cin >> p >> q;
    d = mdc (p, q);
    p /= d, q /= d;
    palindromo ();

    int ans = 0;
    for (int i = 1; i < MAX; i++) {
        if ((ll) pi[i]*p <= (ll) q*rub[i])
            ans = i;
    }

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

#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

const int maxn = 10000010;

int isprime[maxn];
int ispalin[maxn];

void erat() {
	for ( int i = 2 ; i < maxn ; i ++ ) isprime[i] = 1;
	for ( int i = 2 ; i < maxn ; i ++ )
		if ( isprime[i] )
			for ( int j = i * 2 ; j < maxn ; j += i ) isprime[j] = 0;
	for ( int i = 2 ; i < maxn ; i ++ ) isprime[i] += isprime[i-1];
}

void palin() {
	vector < int > v;
	for ( int i = 1 ; i < maxn ; i ++ ) {
		v.clear();
		int x = i;
		while ( x ) {
			v.push_back(x%10);
			x /= 10;
		}
		int ok = 1;
		for ( int j = 0 ; j < v.size() / 2 ; j ++ )
			if ( v[j] != v[v.size() - j - 1] ) {
				ok = 0;
				break;
			}
		if ( ok ) ispalin[i] = 1;
	}
	for ( int i = 1 ; i < maxn ; i ++ ) ispalin[i] += ispalin[i-1];
}

int main() {

	int p,q;
	cin >> p >> q;

	erat();
	palin();

	int rez = -1;
	for ( int i = 1 ; i < maxn ; i ++ ) {
		if ( q * isprime[i] <= p * ispalin[i] ) rez = i;
	}

	cout << rez << endl;
}

#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 <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>

#define ENP     printf("**Entry Point**\n")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef vector  <double>            vec_d;
typedef vector  <vec_d>             vvec_d;
typedef vector  <int>               vec_i;
typedef vector  <vec_i>             vvec_i;
typedef pair    <int, int>          pair_i;
typedef pair    < pair_i, pair_i >  pp_i;

const int INF = 0x7fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 30000001;

bool isP[100000001];
int rubarr[cons];
vector <int> prime;

int mypow(int a, int b)
{
    int ret = 1;
    while (b--)
    {
        ret *= a;
    }

    return ret;
}

int rub(int n)
{
    int num = 0;
    int tmp = n;
    while (tmp)
    {
        num++;
        tmp /= 10;
    }

    int ret = 0;

    for (int i = 1; i < num; i++)
    {
        ret += 9 * mypow(10, (i - 1) / 2);
    }

    if (num % 2 == 0)
    {
        tmp = mypow(10, num / 2);
        tmp = n / tmp;
        int tmp2 = 0;
        int tmp3 = tmp;
        while (tmp3)
        {
            tmp2 *= 10;
            tmp2 += tmp3 % 10;
            tmp3 /= 10;
        }

        tmp = tmp*mypow(10, num / 2);
        tmp += tmp2;

        ret += n / mypow(10, num / 2) - mypow(10, num / 2 - 1);

        if (n >= tmp)
        {
            return 1 + ret;
        }
        else
        {
            return ret;
        }
    }
    else
    {
        int tmp2 = 0;
        int tmp3 = n/ mypow(10, num / 2 + 1);
        while (tmp3)
        {
            tmp2 *= 10;
            tmp2 += tmp3 % 10;
            tmp3 /= 10;
        }

        tmp = (n / mypow(10, num / 2))*mypow(10, num / 2);
        tmp += tmp2;

        ret += n / mypow(10, num / 2) - mypow(10, num / 2);

        if (n >= tmp)
        {
            return 1 + ret;
        }
        else
        {
            return ret;
        }
    }
}

void bp(int n)
{
    memset(isP, true, sizeof(isP));

    isP[0] = isP[1] = false;

    int sqrtn = sqrt(n);
    for (int i = 2; i <= sqrtn; i++)
    {
        if (isP[i] == false)continue;
        for (int j = i*i; j <= n; j+= i)
        {
            isP[j] = false;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        if (isP[i])
            prime.push_back(i);
    }
}

int pi(int n)
{
    int x = upper_bound(prime.begin(), prime.end(), n) - prime.begin();

    return x;
}

int bins(int p, int q)
{
    int h = 30000000;
    int l = 0;

    int cnt = 0;

    while (l + 200000 < h)
    {
        cnt++;
        int mid = l + h >> 1;

        if (q*pi(mid) <= p*rubarr[mid])
        {
            l = mid;
        }
        else
        {
            h = mid;
        }
    }

    int ret = -1;

    for (int i = l; i <= h; i++)
    {
        if (q*pi(i) <= p*rubarr[i])
        {
            ret = i;
        }
    }

    return ret;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

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

    for (int i = 1; i < cons; i++)
    {
        rubarr[i] = rub(i);
    }

    int res = bins(p, q);

    if (res == -1)
    {
        puts("Palindromic tree is better than splay tree");
    }
    else
        printf("%d\n", res);

    return 0;
}

// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=2e7;
bool p[N+5];
int pi[N+5],ru[N+5];

void sieve(){
	p[0]=p[1]=true;
	for(int i=2;i*i<=N;i++)if(!p[i])
		for(int j=i*i;j<=N;j+=i)p[j]=true;
}

void build(){
	sieve();
	FER(i,2,N)pi[i]=pi[i-1]+(!p[i]);
	int lvl=10;
	FER(i,1,10){
		ru[i]++;
		ru[10*i+i]++;
	}
	FER(i,1,10)FER(j,0,10){
		int val1=100*i+10*j+i;
		int val2=1000*i+100*j+10*j+i;
		ru[val1]++;ru[val2]++;
	}
	FER(i,1,10)FER(j,0,10)FER(k,0,10){
		int val1=10000*i+1000*j+100*k+10*j+i;
		int val2=100000*i+10000*j+1000*k+100*k+10*j+i;
		ru[val1]++;
		ru[val2]++;
	}
	FER(i,1,2)FER(j,0,10)FER(k,0,10)FER(e,0,10){
		int val1=1000000*i+100000*j+10000*k+1000*e+100*k+10*j+i;
		int val2=10000000*i+1000000*j+100000*k+10000*e+1000*e+100*k+10*j+i;
		ru[val1]++;
		ru[val2]++;
	}
	FER(i,1,N)ru[i]+=ru[i-1];
}

int pp,qq;

bool cmp(int a,int b){
	return qq*a<=pp*b;
}

int main(){
	fastio;
	build();
	cin>>pp>>qq;
	int ans=-1;
	FER(i,1,N)if(cmp(pi[i],ru[i]))ans=max(ans,i);
	if(ans==-1)cout<<"Palindromic tree is better than splay tree"<<endl;
	else cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

inline bool palindrome(const ll& x) {
    static ll t1 = x, t2 = 0;
    while (t1) {
        t2 = t2 * 10 + (t1 % 10);
        t1 /= 10;
    }
    return x == t2;
}

bool prime[(ll)1e7 + 5];

int main() {
    ll cnt1 = 0, cnt2 = 0, res = 0, p, q;
    cin >> p >> q;
    for (ll i = 2; i <= 1e7; i++) prime[i] = 1;
    for (ll i = 2; i <= 5e6; i++)
        if (prime[i])
            for (ll j = i << 1; j <= 1e7; j += i)
                prime[j] = false;
    for (ll i = 1; i <= 1e7; i++) {
        cnt1 += palindrome(i);
        cnt2 += prime[i];
        if (q * cnt2 <= p * cnt1) res = i;
    }
    return cout << res, 0;
}

#include<bits/stdc++.h>

#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
// mikti prikoldar
#define ll long long
#define pb push_back
#define sz(a) (int)(a.size())
//everything goes according to the plan
#define y1 kek
#define left leftside
#define right rightside
//countdown BEGAN. 10 , 9 , 8 ...
const int Mod = (int)1e9 + 7;
const int MX = 1073741735;
const ll MXLL = 9223372036854775807;
const int Sz = 3110111;
// ai dyn dyn dyn dirindai ai dyn dyn dirindai
using namespace std;
// skr skr skr v temnix naikah
inline void rcin () {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);	cout.tie(NULL);
}
bool p[Sz];
int a[Sz] , p1 , q, pi[Sz] , rub[Sz] , N , n;

inline void Primes () {
	p[1] = 1;
	for (int i = 2;i * i <= N;i ++) {
		if (!p[i])
			for (int j = i * i;j <= N;j += i)	p[j] = 1;
	}
	for (int i = 1;i <= N;i ++)
		pi[i] = pi[i - 1] + (p[i] == 0);
}
bool Pal (int x) {
	vector <int> a;
	while (x) {
		a.pb (x % 10);
		x /= 10;
	}
	for (int i = 0;i < sz(a) / 2 + (sz(a) & 1);i ++)
		if (a[i] != a[sz(a) - i - 1])	return 0;
	return 1;
}
inline void Palindroms () {
	for (int i = 1;i <= N;i ++)
		rub[i] = rub[i - 1] + Pal (i);
}

int main()
{
	rcin ();
	cin >> p1 >> q;

	double A = (double) p1 / q;
	N = (int)1e6;
	Primes ();
	Palindroms ();

	for (int i = 1;i <= N;i ++)
		if (pi[i] <= (double) rub[i] * A) {
			n = i;
		}	else	break;

   if (!n) {
   	cout << "Palindromic tree is better than splay tree";
  	}	else	cout << n;
   return 0;
}

#define ll long long
#define pii pair<ll,ll>
#define m_p  make_pair
#define ull unsigned long long
#include <bits/stdc++.h>
using namespace std;
ll cnt[70][2];
const ll N = 1e5;
ll dp[100004];
ll pal[100004];
void precal()
{

    for(int i=2;i<=N;i++)
    {
        bool flag = true;
        for(int j=2;j*j<=i;j++)
        {
            if(i%j==0)
            {
                flag = false;
                break;
            }
        }

        if(flag)dp[i]=1;
    }

    for(int i=2;i<=N;i++)
    {
        dp[i] = dp[i]+dp[i-1];
    }

    for(int i=1;i<=N;i++)
    {
        string s,txt;
        s = to_string(i);
        txt = s;
        reverse(txt.begin(),txt.end());

        if(txt==s)
            pal[i]=1;
    }

    for(int i=1;i<=N;i++)
    {
        pal[i] = pal[i]+pal[i-1];
    }
}

int main()
{
    double p,q,A,mx=0,res;
    precal();
    ll ans=0,i;

    scanf("%lf %lf",&p,&q);

    A = p/q;

    for(i=1;i<=N;i++)
    {
        res = A*((double)pal[i]);

        if(res>=(double)dp[i])
        {
           ans = i;
        }
    }

    if(!ans)
    {
        printf("Palindromic tree is better than splay tree\n");
    }
    else
    printf("%lld\n",ans);
}

#include<map>
#include<cstdio>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
#define fi first
#define se second
#define debug printf("I am here\n");
using namespace std;
#define int long long
typedef long long ll;
const int maxn=1e6+5,inf=0x3f3f3f3f,mod=1e9+7;
int p,q,t,n,m,prime[maxn],pre1[maxn],pre2[maxn];
bool check(int x){
    int cnt=0,a[10];
    while(x){
        a[++cnt]=x%10;
        x=x/10;
    }
    for(int i=1;i<=cnt/2;i++){
        if(a[i]!=a[cnt-i+1]){
            return 0;
        }
    }
    return 1;
}
void init(){
    prime[1]=0;
    for(int i=2;i<=1e4;i++){
        if(prime[i]==0){//质数
            for(int j=i*i;j<=1e4;j+=i){
                prime[j]=1;
            }
        }
        pre1[i]=pre1[i-1]+(prime[i]==0);
        //[1,i]有多少个质数
    }
    pre2[0]=1;
    for(int i=1;i<=1e4;i++){
        if(check(i)){
            pre2[i]=pre2[i-1]+1;
        }else{
            pre2[i]=pre2[i-1];
        }
//        printf("%d ",pre2[i]);
    }
}
signed main(){
    init();
    int ans=-1;
    scanf("%d%d",&p,&q);
    for(int i=1;i<=1e4;i++){
        if(1ll*pre1[i]*q<=1ll*pre2[i]*p){
//            printf("%d\n",i);
            ans=i;
        }
    }
    if(ans==-1){
        printf("Palindromic tree is better than splay tree\n");
    }else{
        printf("%d\n",ans);
    }
    return 0;
}

/* created   : 2020-05-17 18:10:25
 * accepted  : 2020-05-17 22:20:59
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
typedef long long ll;

template <int N>
bitset<N> sieve() {
  bitset<N> bs;
  bs.set();
  bs[0] = 0;
  bs[1] = 0;
  for (int i = 2; i < N; i++) {
    if (bs.test(i)) {
      for (int j = i + i; j < N; j += i) {
        bs.reset(j);
      }
    }
  }
  return bs;
}

bool check(int x) {
  string s = to_string(x);
  int lo = 0, hi = (int) s.size() - 1;
  while (lo <= hi) {
    if (s[lo] != s[hi]) {
      return false;
    }
    lo++, hi--;
  }
  return true;
}

void solve() {
  int p, q; cin >> p >> q;
  const int N = 1e7;
  auto bs = sieve<N>();
  vector<int> ps(N);
  for (int i = 1; i + 1 < N; i++) {
    ps[i + 1] = ps[i] + bs[i];
  }
  vector<int> pa(N);
  for (int i = 1; i + 1 < N; i++) {
    pa[i + 1] = pa[i] + check(i);
  }
  for (int i = N - 1; i >= 1; i--) {
    if (ps[i] * q <= pa[i] * p) {
      cout << i - 1 << "\n";
      return;
    }
  }
  cout << "Palindromic tree is better than splay tree\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}

#pragma comment(linker, "/stack:32000000")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#include <functional>
#include <stack>
#include <cstring>
#include <locale>
#include <cstdio>

using namespace std;

#define ll long long
#define ull unsigned ll
#define mp(a,b) (make_pair(a,b))
#define vv(a, n, m, v) vector<vector<a>> v(n, vector<a>(m))

#define Y first
#define X second
#define lendl cout<<endl
#define INF (ll)1e18
#define PR (ll)1000003
#define OST (ll)1000003
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double, double>
#define EPS (double)1e-9
#define PI (double)3.1415926535897
#define vi vector<int>
#define vii vector< vi >
#define vl vector<ll>
#define vll vector< vl >
#define vc vector<char>
#define vs vector<string>
int n, m, k;

void ToLower(string& s) {
	for (int i = 0; i < s.length();) {
		if (!(s[i] >= -1 && s[i] <= 255) || !isalpha(s[i]))
			s.erase(s.begin() + i);
		else i++;
	}

	for (int i = 0; i < s.length(); i++) {
		s[i] = tolower(s[i]);
	}
}
string ToString(int val) {
	string res = "";
	while (val > 0) {
		res += (val % 10) + '0';
		val /= 10;
	}
	reverse(res.begin(), res.end());
	return res;
}

vii gr;

bool IsPalindrome(int& val) {
	string str = ToString(val);
	int len = str.length();
	for (int i = 0; i < len; i++) {
		if (str[i] != str[len - i - 1])
			return false;
	}
	return true;
}
const int top = 3e6;
char prime[top + 10];
int main() {
#ifndef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//string _file_name_ = "repair";
	//freopen((_file_name_ + ".in").c_str(), "r", stdin); freopen((_file_name_ + ".out").c_str(), "w", stdout);
#endif

	int p ,q;
	cin >> p >> q;
	 //1e8 = 1500 ctr  5761455

	//vector<char> prime(top + 1, true);
	std::fill(prime, prime + top + 10, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i <= top; ++i)
		if (prime[i])
			if (i * 1ll * i <= top)
				for (int j = i*i; j <= top; j += i)
					prime[j] = false;

	int _cnt1 = 0;
	int _cnt2 = 0;
	int ans = 0;
	for (int i = 1; i < top; i++) {
		_cnt2 += IsPalindrome(i);
		_cnt1 += prime[i];
		if ((ll)_cnt1 * q <= (ll)_cnt2 * p) {
			ans = i;
		}

	}
	cout << ans;
	return 0;
}

#include <stdio.h>
#include<iostream>
using namespace std;
const int N=1100001;
int prime[N];
int sum[N],sumr[N];
int rep[N];
bool calc(int x)
{
	string s="";
	while(x>0)
	{
		int d=x%10;
		x/=10;
		char temp=d+'0';
		s+=temp;
	}
	for(int i=0;i<s.length()/2;++i)
	{
		if(s[i]!=s[s.length()-i-1])
		{
			return false;
		}
	}
	return true;
}
int main(){
    prime[1]=1;
    for(int i=2;i*i<=N;i++){
        if(!prime[i]){
            for(int j=i*i;j<=N;j+=i){
                prime[j]=1;
            }
        }
    }
    for(int i=1;i<N;++i)
    {
		sum[i]=sum[i-1]+!prime[i];
	}
	for(int i=1;i<N;++i)
	{
		if(calc(i))
			rep[i]=1;
		if(i!=0)
			sumr[i]=sumr[i-1]+rep[i];
		else
			sumr[i]=rep[i];
	}
    long long p ,q;
    cin>>p>>q;
    int ans=-1;
    for(int i=1;i<N;++i)
    {
		if(q*sum[i]<=p*sumr[i])
			ans=i;
	}
	if(ans!=-1)
		cout<<ans;
	else
		cout<<"Palindromic tree is better than splay tree"<<endl;

}

//Khodaya aghideye man ra az dast oghde am masoon dar!
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using ordered_set =  tree<T, null_type, greater<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long ll;
typedef long double ld;
#pragma optimize O3
const int MOD = (int)1e9 + 7;
const int MAXN = (int)3e6 + 7;
const int MAXS = (int)502;
const int infint = (ll)1e9;
const ll inf = (ll)1e18;
int prime[MAXN];
bool ok(int i)
{
	int rev = 0, tmp = i;
	while(tmp)
	{
		rev = rev * 10 + (tmp % 10);
		tmp /= 10;
	}
	if(rev == i)
		return 1;
	else
		return 0;
}
int main()
{
	int p, q;
	cin >> p >> q;
	prime[1] = 1;
	for (int i = 2; i < MAXN; i++)
		if(prime[i] == 0)
			for (int j = 2 * i; j < MAXN; j += i)
				prime[j] = 1;
	int mx = -1, tpr = 0, tpal = 0;
	for (int i = 1; i < MAXN; i++)
	{
		if(prime[i] == 0)
			tpr++;
		if(ok(i))
			tpal++;
		if(q * tpr <= p * tpal)
			mx = i;
	}
	if(mx == -1)
		cout << "Palindromic tree is better than splay tree";
	else
		cout << mx;
}

///===========================///
///                           ///
///    UserID : L1nK1n        ///
///    UnivID : CSE, JU       ///
///                           ///
///===========================///

//#pragma warning (disable: 4786)
//#pragma comment (linker, "/STACK:16777216")

#include "bits/stdc++.h"

#define P   printf
#define S   scanf
#define D   double
#define ll  long long
#define ULL unsigned long long

#define S1(a)      S("%d",&a)
#define S2(a,b)    S("%d%d",&a,&b)
#define S3(a,b,c)  S("%d%d%d",&a,&b,&c)
#define SL1(a)     S("%lld",&a)
#define SL2(a,b)   S("%lld%lld",&a,&b)
#define SL3(a,b,c) S("%lld%lld%lld",&a,&b,&c)

#define DI(X)        int X;     S("%d", &X)
#define DII(X,Y)     int X,Y;   S("%d%d", &X, &Y)
#define DIII(X,Y,Z)  int X,Y,Z; S("%d%d%d", &X, &Y, &Z)
#define DLI(X)       ll X;      S("%lld", &X)
#define DLII(X,Y)    ll X,Y;    S("%lld%lld", &X, &Y)
#define DLIII(X,Y,Z) ll X,Y,Z;  S("%lld%lld%lld", &X, &Y, &Z)

#define FL(i, a, b)    for(int i=a; i<b; i++)
#define RFL(i, a, b)   for(int i=a; i>=b; i--)
#define FLI(i,a,b,inc) for(int i=a; i<b; i+=inc)
#define FLD(i,a,b,dec) for(int i=a; i>=b; i-=dec)
#define FS(x)          for(typeof (x.begin()) it = x.begin(); it != x.end (); it++)
#define PR(x)          for(typeof (x.begin()) it = x.begin(); it != x.end (); it++) cout << *it << " "; cout << endl;

#define PC(a)  printf("Case %d: ",a)
#define PCN(a) printf("Case %d:\n",a)
#define PCH(a) printf("Case #%d: ",a)

#define xx  first
#define yy  second
#define MP  make_pair

#define MEM(a,val) memset(a,val,sizeof a)
#define SET(a)     memset(a,-1,sizeof a)
#define CLR(a)     memset(a,0,sizeof a)

#define lb       lower_bound
#define ub       upper_bound
#define LB(a,x) (lower_bound(ALL(a),x)-a.begin())
#define UB(a,x) (upper_bound(ALL(a),x)-a.begin())

#define PI(x)    P("%d\n", x)
#define PL(x)    P("%lld\n", x)
#define pi       2.0*acos(0.0)
#define EPS      1e-11
#define SQR(n)   (n*n)
#define ALL(a)   a.begin(),a.end()
#define nl       P("\n")
#define CHECK    P("here\n")
#define GCH()    getchar()
#define pb       push_back
#define pp       pop_back
#define PF(x)    push_front(x)
#define PPF(x)   pop_front()
#define ps(x)    push(x)
#define SZ(w)    ((int)w.size())
#define SUM(a,n) accumulate(a,a+n,0)
#define COUNT1(x) __builtin_popcount(x)
#define DBUG(n)  P("Done %d\n",n);
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define _cin     ios_base::sync_with_stdio(false); cin.tie(NULL);

#define _max(a,b,c) max(a,max(b,c))
#define _min(a,b,c) min(a,min(b,c))
#define mxe(a,n)    *max_element(a,a+n)
#define mne(a,n)    *min_element(a,a+n)
#define mxev(a)     *max_element(ALL(a))
#define mnev(a)     *min_element(ALL(a))

using namespace std;

template <typename T> T euclide(T a,T b,T &x,T &y) {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;} if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}
template <typename T> T BigMod(T b,T p,T m){if(p==0) return 1;if(p%2==0){T s=BigMod(b,p/2,m);return ((s%m)*(s%m))%m;}return ((b%m)*(BigMod(b,p-1,m)%m))%m;} //linKin_cse22_ju//
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
template <typename T> T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b){if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
template <typename T> T ModInv(T b,T m){ return BigMod(b,m-2,m); }
template <typename T> T Dis(T x1,T y1,T x2, T y2){return sqrt( SQR(abs(x1-x2)) + SQR(abs(y1-y2)) );}
template <typename T> T Angle(T x1,T y1,T x2, T y2){ return atan( double(y1-y2) / double(x1-x2));}
template <typename T> ll isLeft(T a,T b,T c) { return (a.x-b.x)*(b.y-c.y)-(b.x-c.x)*(a.y-b.y); }
template <typename T> T iArray(T a[],int n){for (int i=0; i<n; i++) cin >> a[i];}
template <typename T> T pArray(T a[],int n){for (int i=0; i<n-1; i++) cout << a[i] << " ";cout << a[n-1] << endl;}
template <typename T> T nextInt(){char ch;T n = 0;bool ng = false;while (1){ch = getchar();if (ch == '-'){ng = true;ch = getchar();break;}if (ch>='0' && ch<='9') break;}while (1){n = n*10 + (ch - '0');ch = getchar();if (ch<'0' || ch>'9') break;}return (ng?-n:n); }

template < class T, class X > inline bool checkbit(T a, X pos)  { T t=1;return ((a&(t<<pos))>0); }
template < class T, class X > inline  T   onbit(T a, X pos)     { T t=1;return (a|(t<<pos));     }
template < class T, class X > inline  T   offbit(T a, X pos)    { T t=1;return (a&(~(t<<pos)));  }
template < class T, class X > inline  T   togglebit(T a, X pos) { T t=1;return (a^(t<<pos));     }
template < class T > string NTS ( T Number ){stringstream ss;ss << Number;return ss.str();}

double DEG(double x) { return (180.0*x)/(pi); }
double RAD(double x) { return (x*(double)pi)/(180.0); }
int cdigittoint(char ch){ return ch-'0'; }
int toInt(string s){ int sm; stringstream ss(s); ss>>sm; return sm; }
ll toLLInt(string s){ ll sm; stringstream ss(s); ss>>sm; return sm; }
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U') return true; return false; }
bool isConst(char ch){ if (isalpha(ch) && !isVowel(ch)) return true; return false; }
bool isprime(int w){if(w == 0) return false;if(w == 1) return false;int sqrtw = int(sqrt((double)w));for(int q = 2; q <= sqrtw; q++){if(w % q == 0) return false;}return true;}

///int dx[]={0,1,0,-1};int dy[]={1,0,-1,0};                       //4 Direction//
///int mnth[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};           //Year Derection//
///int dx[]={-1,-1,+0,+1,+1,+0};int dy[]={-1,+1,+2,+1,-1,-2};     //Hexagonal Direction//
///int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};   //8 Direction//
///int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1}; //Knight Direction//

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpi;

const int MX  = 1000050;
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LINF = LONG_LONG_MAX;

///.............End Of Template..............///

int vis[47007], prm[4797], cpp[10009], cp[10009];
int i, j, p, k;

void sieve()
{
    prm[p++] = 2;
    for(i = 3; i*i <= 10000; i+=2){
        if(!vis[i]){
            prm[p++] = i;
            for(j = i+i; j <= 10000; j += i){
                vis[j] = 1;
            }
        }
    }
    for(; i < 10001; i+=2) if(!vis[i]){
        prm[p++] = i;
    }
}

main(int argc, char const* argv[]) {

    sieve();
    D p,q;
    scanf("%lf%lf", &p,&q);
    double d = (double) (p/q);
    int k, mx=0, cnt=0;
    for(int i2 = 1; i2 <= 10000; i2++){
        string s1 = NTS(i2);
        string s2 = s1;
        reverse(ALL(s2));
        if(s1 == s2) cnt++;
        cpp[i2] = cnt;
    }
    int cnt1=0;
    for(int i1 = 1; i1 <= 10000; i1++){
        if(isprime(i1)) cnt1++;
        cp[i1] = cnt1;
    }
    for(k = 1; k <= 10000; k++){
        D p1 = (double) cp[k];
        D p2 = (double) cpp[k];
        if(p1 <= (double)(d*p2)){
            mx = max(mx, k);
        }
    }
    if(mx ==0) cout << "Palindromic tree is better than splay tree\n";
    else PI(mx);
}

#include <iostream>

using namespace std;
long long p, q, notprime[5000000], pal[5000000], kpr[5000000], kpal[5000000];
long long pal1(long long i)
{
    long long ans=i;
    while(i!=0)
    {
        ans=ans*10+i%10;
        i=i/10;
    }
    return ans;
}
long long pal2(long long i)
{
    long long ans=i;
    i=i/10;
    while(i!=0)
    {
        ans=ans*10+i%10;
        i=i/10;
    }
    return ans;
}

int main()
{
    cin >> p >> q;
    for(int i=2;i<5000;i++)
        for(int j=i*i;j<5000000;j+=i)
        notprime[j]=1;
    notprime[1]=1;
    for(int i=1;i<50000;i++)
    {
        if(pal1(i)<5000000)
            pal[pal1(i)]=1;
        if(pal2(i)<1000000)
            pal[pal2(i)]=1;
    }
    for(int i=1;i<5000000;i++)
    {
        kpr[i]=kpr[i-1];
        kpal[i]=kpal[i-1];
        if(notprime[i]==0)
            kpr[i]++;
        if(pal[i]==1)
            kpal[i]++;
    }
    int i=4999999;
    while(i>=1 && kpr[i]*q>kpal[i]*p)
    {
        i--;
    }
    cout << i;
    return 0;
}

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define md int(1e7+100)
#define modul int(1e9+7)
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;
typedef long long ll;

bool check(int u);

int p, q, l, Pi, rub, res, a[10], nt[50000010];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> p >> q;
    FOR(i,2,50000000)
        if (nt[i] == 0)
            for (int j = 1; j*i <= 50000000; j++)
                if (nt[j*i] == 0) nt[j*i] = i;
    res = -1;
    nt[0] = -1;
    FOR(i,1,50000000) {
        if (nt[i] == i) Pi++;
        if (i == 0 || check(i)) rub++;
        if (Pi * q <= rub * p) res = i;
    }
    if (res == -1) cout << "Palindromic tree is better than splay tree";
    else cout << res;
    return 0;
}

bool check(int u)
{
    if (u % 10 == 0) return false;
    int d = 0;
    while (u > 0) {
        a[++d] = u%10;
        u /= 10;
    }
    FOR(i,1,d/2)
        if (a[i] != a[d-i+1]) return false;
    return true;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;
int p,q,a[2000005],sum1[2000005],sum2[2000005];
void prime(int n){
int j,data=0,i;
for(i=2;i<=n;i++){
    if(a[i]==0){
        data++;
        for(j=2*i;j<=n;j+=i)
            a[j]=data;
    }
}
return ;
}
bool  dromic(int n){
int sum[15],j,j1;
if(n<10)
    return true;
for(j=1;;j++){
        sum[j]=n%10;
        n/=10;
        if(n==0)
            break;
    }
    for( j1=1;j1<=j/2;j1++){
    if(sum[j]!=sum[j1])
         break;
    }
if(j1>j/2)
return true;
else
    return false;
}
int main()
{
   //freopen("in.txt","r",stdin);
cin>>p>>q;
if(p==0)
cout<<"Palindromic tree is better than splay tree"<<endl;
else if(q==0)
cout<<1<<endl;
else {
   int i;
   prime(2000005);
sum1[2]=1;
for(i=3;i<=2000000;i++){
    sum1[i]=sum1[i-1];
    if(a[i]==0)
    sum1[i]++;
}
   sum2[1]=1;
   for(i=2;i<=2000000;i++){
    sum2[i]=sum2[i-1];
    if(dromic(i))
        sum2[i]++;
   }
    int ans=-1;
    for(int i=0;i<=2000000;i++){
    if(sum1[i]*q<=p*sum2[i])
        ans=max(ans,i);
    }
   // cout<<sum2[11]<<endl;
    if(ans==-1)
        cout<<"Palindromic tree is better than splay tree"<<endl;
    else
    cout<<ans<<endl;
}
 return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ALL(v) ((v).begin()), ((v).end())
#define INCREASING(v) sort(ALL(v))
#define DECREASING(v) INCREASING(v), reverse(ALL(v))
#define LP(c,x,n)  for(int c=x;c<n;++c)
#define MOD(a,n) ((a%n+n)%n)
#define LO(c,n,x)  for(int c=n;c>=x;c--)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PB push_back
#define F first
#define S second
#define SZ(x) (int(x.size()))
#define num1(x) __builtin_popcount(x)
#define STP(x) setprecision(x)
#define PI ( 2 * acos(0.0))
#define EPS 1e-9
#define INF 1.0/0.0
#define Yala_Besor3a ios_base::sync_with_stdio(0),ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
using namespace std;
const int OO = 0x3f3f3f3f,NegOO= -1*OO,N =1e7+5;
const int maxarr=N;
bool prime[maxarr];
void Sieve()
{
    memset(prime,1,sizeof(prime));
    prime[0]=prime[1]=0;
    for(int c=2; c*c<=maxarr; c++)
    {
        for(int i=2*c; i<maxarr; i+=c)prime[i]=0;
    }
}
bool palindrome(string x)
{
    LP(c,0,SZ(x)/2)
    {
        if(x[c]!=x[SZ(x)-c-1])return 0;
    }
    return 1;
}
string intToString(int num){
    string ans;
    while(num){
        ans+=((num%10)+'0'),num/=10;
    }
    reverse(ALL(ans));
    return ans;
}
int main() {
    Sieve();
    int n=1e7;
    int sum=0,sum2=0;
    int  s1,s2,p,q,A;
    cin>>p>>q;
    A=p/q;
    int ans=0;
    LP(c,1,n+1){
        sum+=(prime[c]);
        sum2+=palindrome(intToString(c));
     //   cout<<sum2<<" "<<sum<<" "<<c<<endl;
        if(sum*q<=sum2*p)ans=c;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) (x).begin, (x).end
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll modpow(ll b, ll e ,ll mod) { ll ans = 1;for (; e; b = b * b % mod, e /= 2){if (e & 1) ans = ans * b % mod;}return ans;}
const int N = 1000005;
bool isp[N];
int p[N] , pal[N];

bool ispal(int x){
	vi v;
	while(x > 0){
		v.push_back(x%10);
		x /= 10;
	}
	bool ok = true;
	for(int i = 0 ; i < sz(v) / 2 ; i ++){
		if(v[i] != v[sz(v) - i - 1]) ok = false;
	}
	return ok;
}

int32_t main(){
	for(int i = 2 ; i < N; i ++){
		if(!isp[i]){
			p[i] ++ ;
			for(int j = i ; j < N ; j += i) isp[j] = 1;
		}
		p[i] += p[i-1];
	}
	for(int i = 1 ; i < N ; i ++){
		pal[i] = pal[i-1] + ispal(i);
	}
	int P , Q;
	cin >> P >> Q;
	int ans = -1;
	for(int i = 1 ; i < N ; i ++){
		if(Q*p[i] <= P*pal[i]) ans = max(ans , i);
	}
	cout << ans << endl;
}
/* clever stuff:
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and STAY ORGANIZED
	* Keep it simple stupid
	* WRITE STUFF DOWN
	* math -> gcd / lcm / divisors?
*/

#include<bits/stdc++.h>
using namespace std;
bool prime[1000005];
long prefix[1000005];
bool palin[1000005];
long prefix1[1000005];
void seive()
{
    memset(prime,true,sizeof(prime));
    long i,p;
    prime[0]=prime[1]=false;
    for(p=2;p<=1000005/2;p++)
    {
        for(i=2*p;i<1000005;i+=p)
            prime[i]=false;
    }
    prefix[0]=0;
    for(i=1;i<1000005;i++)
    {
        prefix[i]=prefix[i-1];
        if(prime[i]==true)
            prefix[i]++;
    }
}

bool chk(string geek)
{
    int k = geek.size();
    int i;
    for(i=0;i<k/2;i++)
    {
        if(geek[i]!=geek[k-1-i])
            return(false);
    }
    return(true);
}
void pal()
{
    memset(palin,false,sizeof(palin));
    long i;

    bool p;
    for(i=1;i<1000005;i++)
    {
      ostringstream str1;
      str1 << i;
      string geek = "";
      geek = str1.str();
      p = chk(geek);
      // if(i==1)
      //cout << geek << endl;
      if (p == true)
        palin[i] =true;
    }
    prefix1[0]=0;
    for(i=1;i<1000005;i++)
    {
        prefix1[i]=prefix1[i-1];
        if(palin[i]==true)
            prefix1[i]++;
    }
}
int main()
{
    seive();
    pal();
    long p,q;
    cin>>p>>q;
    long i;
    i=1;
    long i_m=1;
    for(i=1;i<1000005;i++)
    {
        if(prefix[i]<=(prefix1[i]*p)/q)
            i_m=max(i_m,i);
    }
    cout<<i_m<<endl;
}

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

const int N = 1e7 + 10;
const int LIM = 1e7;

int p, q;
int prime[N], tot;
bool vis[N];
bool is_prime[N], is_plr[N];
vector<int> all;

void init() {
    cin >> p >> q;
}

void get_prime_number() {
    for (int i = 2; i <= LIM; i ++) {
        if (vis[i] == false) {
            prime[++tot] = i;
            is_prime[i] = true;
            all.push_back(i);
        }
        for (int j = 1; j <= tot; j ++) {
            long long t = i * prime[j];
            if (t > LIM) {
                break;
            }
            vis[t] = true;
            if (i % prime[j] == 0) {
                break;
            }
        }
    }
}

bool check_plr(string x) {
    for (int i = 0; i < (int)x.length(); i ++) {
        int t = (int)x.length() - i - 1;
        if (t <= i) {
            return true;
        }
        if (x[i] != x[t]) {
            return false;
        }
    }
    return true;
}

void get_palindrome_number() {
    for (int i = 1; i <= 10000; i ++) {
        stringstream ss;
        string t;

        ss << i;
        ss >> t;

        if (check_plr(t)) {
            is_plr[i] = true;
            all.push_back(i);
        }
    }
}

void work() {
    get_prime_number();
    get_palindrome_number();

    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());

    int cnt_prime = 0, cnt_plr = 0;
    int ans = -1;
    for (int i = 0; i + 1 < (int)all.size(); i ++) {
        cnt_prime += is_prime[all[i]];
        cnt_plr += is_plr[all[i]];

        if ((long long)cnt_prime * q <= (long long)cnt_plr * p) {
            ans = max(ans, all[i + 1] - 1);
        }
    }

    if (ans == -1) {
        cout << "Palindromic tree is better than splay tree" << endl;
    } else {
        cout << ans << endl;
    }
}

int main() {
    //freopen("A.in", "r", stdin);

    init();
    work();

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ps push
#define pf push_front
#define mp make_pair
#define And &&
#define Or ||
#define inf INT_MAX
#define sz(name) name.size()
#define len(name) name.length()
#define ig cin.ignore()
#define sc1(name) scanf("%d",&name)
#define sc2(name1,name2) scanf("%d%d",&name1,&name2)
#define sc3(name1,name2,name3) scanf("%d%d%d",&name1,&name2,&name3)
#define scl1(name) scanf("%lld",&name)
#define scl2(name1,name2) scanf("%lld%lld",&name1,&name2)
#define scl3(name1,name2,name3) scanf("%lld%lld%lld",&name1,&name2,&name3)
#define Sort(name) sort(name.begin(),name.end())
#define SSort(name) sort(name.rbegin(),name.rend())
#define For(name,start,finish) for(int name=start;name<finish;name++)
#define Forr(name,start,finish) for(int name=start;name>=finish;name--)
#define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//int row[]={0,1,0,-1};
//int col[]={1,0,-1,0};

const ll N=2e6+10;
const ll M=1e18+7;
const ll H=1e9+7;
const ll base=131;

ll logx(ll a,ll bs){return log(a)/log(bs);}
ll Max(ll a,ll b){if(a>b)return a;return b;}
ll Min(ll a,ll b){if(a>b)return b;return a;}
ll big_mul(ll a,ll b,ll m){ll x=0,y=a%m;while(b>0){if(b&1)x=(x+y)%m;y=(2*y)%m;b>>=1;}return x%m;}
ll big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=(x*y)%m;y=(y*y)%m;b>>=1;}return x%m;}
ll Big_mod(ll a,ll b,ll m){ll x=1,y=a%m;while(b>0){if(b&1)x=big_mul(x,y,m);y=big_mul(y,y,m);b>>=1;}return x%m;}
ll mod_inverse(ll a,ll m){return big_mod(a,m-2,m);}  //a^-1 mod m = a^(m-2) mod m
ll GCD(ll a,ll b){if(!a)return b;return GCD(b%a,a);}

bool vis[N];
ll ara1[N];
ll ara2[N];

void sieve()
{
    vis[1]=true;

    for(int i=4;i<N;i+=2)
        vis[i]=true;

    for(int i=3;i<=sqrt(N);i+=2)
    {
        if(vis[i]==false)
        {
            for(int j=i*i;j<N;j+=i+i)
                vis[j]=true;
        }
    }

    For(i,1,N)
    ara1[i]=ara1[i-1]+!vis[i];

}

bool palindrome(int n)
{
    vector<int> tmp;

    while(n)
    {
        tmp.pb(n%10);
        n/=10;
    }

    for(int i=0,j=sz(tmp)-1;i<j;i++,j--)
    {
        if(tmp[i]!=tmp[j])
            return false;
    }

    return true;

}

int main()
{
    fast_in_out

    sieve();//cout<<"asd"<<endl;

    For(i,1,N)
    ara2[i]=ara2[i-1]+palindrome(i);cout<<"ert"<<endl;

    ll p,q;
    cin>>p>>q;

    int ans=0;

    For(i,1,N)
    {
        if(q*ara1[i]<=p*ara2[i])
            ans=i;
    }

    //cout<<ara1[172]<<" "<<ara2[172]<<" "<<ara1[108]<<" "<<ara2[108]<<endl;

    cout<<ans<<endl;

    return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#define maxn 1200000
using namespace std;
bool isPrime[maxn];
int cntPrime[maxn];
int cntHuiwen[maxn];
FILE *out1 = fopen("out1.txt","w");
FILE *out2 = fopen("out2.txt","w");
bool ishuiwen(int n){
    int t = 0;
    int a = n;
    while(n){
        t = t * 10 + n%10;
        n /= 10;
    }
    return t == a;
}
void init(){
    int i,j;
    memset(isPrime,true,sizeof(isPrime));
    isPrime[0] = isPrime[1] = false;
    for(int i = 2;i < maxn;i ++){
        if(isPrime[i]){
            for(int j = 2;i*j < maxn;j ++){
                isPrime[i*j] = false;
            }
        }
    }
    cntPrime[0] = 0;
    for(int i = 1;i < maxn;i ++){
        cntPrime[i] = cntPrime[i-1];
        if(isPrime[i]) cntPrime[i] ++;
        //fprintf(out1,"cntprime[%d] = %d\n",i,cntPrime[i]);
    }
    //printf("cntprime[%d] = %d\n",maxn-1,cntPrime[maxn-1]);
}
void init2(){
    cntHuiwen[0] = 0;
    for(int i = 1;i < maxn;i ++){
        cntHuiwen[i] = cntHuiwen[i-1];
        if(ishuiwen(i))
            cntHuiwen[i] ++;
        //fprintf(out2,"cnthuiwen[%d] = %d\n",i,cntHuiwen[i]);
    }
    //printf("cnthuiwen[%d] = %d\n",maxn-1,cntHuiwen[maxn-1]);
}
int main()
{
    init();
    init2();
    int q,p;
    while(cin >> p >> q){
        int s = 1;
        int e = maxn-1;
        while(s <= e){
            int m = (s+e)/2;
            if(cntPrime[m]*q > cntHuiwen[m]*p)
                e = m-1;
            else
                s = m+1;
        }
        s = s-1;
        int ans = s;
        int len = 20;
        for(int i = 1;i <= 4005;i ++){
            if(cntPrime[s + i]*q <= cntHuiwen[s + i]*p) ans = s + i;
        }
        cout << ans << endl;
    }
    return 0;
}

#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
#define N 2000000
int vis[N], pai[N], rub[N], isp[N], p10[7];
vi prim;

void init() {
  for (int i=2; i<N; i++) {
    if (!vis[i]) prim.push_back(i);
    for (int j: prim) {
      if ((ll)j * i >= N) break;
      vis[j * i] = 1;
      if (i % j == 0) break;
    }
  }
  pai[1] = 0;
  for (int i=2; i<N; i++) pai[i] = pai[i-1] + (1-vis[i]);
  p10[1] = 1;
  for (int i=2; i<7; i++) p10[i] = p10[i-1] * 10;

  for (int i=1; i<10; i++) isp[i] = 1;
  for (int i=2; i<7; i++) {
    int len = i / 2;
    if (i % 2) {
      for (int j=p10[len]; j<p10[len+1]; j++) {
        for (int k=0; k<10; k++) {
          ll v = (ll)j * p10[len+1] * 10 + (ll) k * p10[len+1] + j;
          if (v < N) isp[v] = 1;
        }
      }
    } else {
      for (int j=p10[len]; j<p10[len+1]; j++) {
        ll v = (ll)j * p10[len+1] + j;
        if (v < N) isp[v] = 1;
      }
    }
  }
  for (int i=1; i<N; i++) rub[i] = rub[i-1] + isp[i];
}

void solve(int p, int q) {
  int res = -1;
  for (int i=1; i<N; i++) {
    if (pai[i] * q <= p * rub[i]) res = i;
    //if (i <= 10) printf("i:%d pai:%d rub:%d\n", i, pai[i], rub[i]);
  }
  if (res == -1) {
    cout << "Palindromic tree is better than splay tree" << endl;
  } else {
    cout << res << endl;
  }
}

int main() {
  init();
  int p, q;
  cin >> p >> q;
  solve(p, q);
  return 0;
}

#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define met(a,b) memset(a,b,sizeof(a))
const int maxn = 2000020;
int visited[maxn+10];
int num[maxn+10];
int visited1[maxn+10];
int numx[maxn+10];

int prime(int num)
{
    for(int i=2;i*i<=num;i++)
    if(num%i==0)
        return false;
    return true;
}

void cnt()
{
    met(visited,0);
    for(int i=2;i<=maxn;i++)
    {
        if(prime(i))
            visited[i]=1;
    }
    met(num,0);
    num[1]=0;
    num[2]=1;
    for(int i=3;i<=maxn;i++)
    {
        if(visited[i])
        num[i]=num[i-1]+1;
        else
        num[i]=num[i-1];
    }
}

int change(int num)
{
    int  a[100];
    int b[100];
    int num1=num;
    int num2=num;
    int len1=0;
    int len2=0;
    while(num1)
    {
        a[len1++]=num1%10;
        num1/=10;
    }
    while(num2)
    {
        b[len2++]=num2%10;
        num2/=10;
    }
    int flag=0;
    for(int i=0,j=len2-1;i<len1;i++,j--)
    {
        if(a[i]!=b[j])
        {
            flag=1;
            break;
        }
    }
    if(flag)
        return false;
    return true;
}

void make()
{
    met(visited1,0);
    for(int i=1;i<=maxn;i++)
    {
        if(change(i))
        visited1[i]=1;
    }
    met(numx,0);
    for(int i=1;i<=maxn;i++)
    {
        if(visited[i])
        numx[i]=numx[i-1]+1;
        else
        numx[i]=numx[i-1];
    }
}

int main()
{
    cnt();
    make();
    int p,q;
    while(scanf("%d%d",&p,&q)!=EOF)
    {
        for(int i=maxn;i>=1;i--)
        {
            int num1=num[i];
            int num2=numx[i];
            if(num1*q<=num2*p)
            {
                printf("%d\n",i);
                break;
            }
        }
    }
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ul;

#define all(s) (s).begin(),(s).end()
#define pb push_back
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define INF std::numeric_limits<int>::max()
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

const int MAXN =  1000010;
//const int MAXN = 50;
vector<int> primes(MAXN);
vector<int> palindromes(MAXN);
int main()
{
	IO;
	double p,q; cin >> p >> q;

	for(int i=0;i<MAXN;++i) primes[i]=1;
	primes[0]=0; primes[1]=0;
	for(int i=2;i<=sqrt(MAXN);++i)
	{
		if(primes[i]==1)
		{
			for(int j=i+i;j<MAXN;j+=i)
			{
				primes[j]=0;
			}
		}
	}

	for(int i=0;i<MAXN;++i) palindromes[i]=0;
	for(int i=1;i<MAXN;++i)
	{
		stringstream s;s<<i;
		string t = s.str();
		bool p=true;
		for(int j=0;j<t.length()/2;++j)
		{
			if(t[j]!=t[t.length()-j-1])
			{
				p = false; break;
			}
		}
		if(p) palindromes[i]=1;
	}
	for(int i=1;i<MAXN;++i)
	{
		primes[i]+=primes[i-1];
		palindromes[i]+=palindromes[i-1];
	}
	int i=1; int ma=0;
	while(i<MAXN)
	{
		if((primes[i])*q<=p*(palindromes[i]))
		{
			ma=i;
		}
		i++;

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

//#include "stdafx.h"
#include <iostream>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <string>
typedef  long long ll;

using namespace std;
#define N 105000
int mas[N];
int mas2[N];
bool vis[N];
bool chek(string &s) {
	for (int j = 0; j < s.size() / 2; j++) {
		if (s[j] != s[s.size() - 1 - j]) {
			return false;
		}
	}
	return true;
}
void edc() {
	int k = 0;
	for (int i = 1; i < N; i++) {
		string s = to_string(i);
		if (chek(s)) {
			k++;

		}
		mas[i] = k;
	}
}
void resheto() {
	int k = 0;
	for (int i = 2; i < N; i++) {
		if (vis[i] == false) {
			k++;
			for (int j = i; j < N; j += i) {
				vis[j] = true;
			}
		}
		mas2[i] = k;
	}
}
int main()
{
	edc();
	resheto();
	cout << mas[N-1] << endl;
	cout << mas2[N-1] << endl;
	return 0;
}

#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
#define ld long double
#define ll long long
#define sqr(a) (a)*(a)
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define inf (int)1e9
#define pi pair<int,int>
#define y1 fdfs
using namespace std;
const int N=1e6;
int s[N],p[N],a,b,ans;
char f(int x)
{
    vector<int>a,b;
    while(x)
    {
        a.pb(x%10);
        x/=10;
    }
    b=a;
    reverse(all(b));
    return a==b;
}
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin>>a>>b;
    p[1]=1;
    for(int i=2;i*i<N;++i)
        if(!p[i])
        for(int j=i*i;j<N;j+=i)
            p[j]=1;
    for(int i=1;i<N;++i){
        s[i]=s[i-1]+f(i);
        p[i]=p[i-1]+(!p[i]);
    }
    for(int i=1;i<N;++i)
        if(b*p[i]<=a*s[i]) ans=i;
    cout<<ans;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>

using namespace std;

int p, q;
const int n = 1200000;
vector<char> prime, rb;
vector<int> pi, rub;

int main()
{
    cin >> p >> q;
    prime.resize(n + 1, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i <= n; ++i)
    if (prime[i])
    if (i * 1ll * i <= n)
    for (int j = i*i; j <= n; j += i)
        prime[j] = false;

    int x = 0;
    pi.resize(n + 1);
    for (int i = 1; i <= n; i++)
    {
        if (prime[i]) x++;
        pi[i] = x;
    }

    rb.resize(10000000, false);
    for (int i = 1; i < 10; i++) {
        rb[i] = true;
        rb[10 * i + i] = true;
        for (int j = 0; j < 10; j++) {
            rb[i + 10 * j + 100 * i] = true;
            rb[i + 10 * j + 100 * j + 10000 * i] = true;
            for (int k = 0; k < 10; k++) {
                rb[i + 10 * j + 100 * k + 10000 * j + 100000 * i] = true;
                rb[i + 10 * j + 100 * k + 10000 * k + 100000 * j + 1000000 * i] = true;
            }
        }
    }

    int y = 0;
    rub.resize(n + 1);
    for (int i = 1; i <= n; i++)
    {
        if (rb[i]) y++;
        rub[i] = y;
    }

    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        if (q*pi[i] <= p*rub[i]) res = i;
    }

    cout << res;
    cin >> p;
    return 0;
}

#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <string.h>
#include <queue>
#include <stack>
#include <cmath>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define min(a,b)  (((((a)) < (b)))?((a)):((b)))
#define max(a,b)  (((((a)) > (b)))?((a)):((b)))
#define abs(a)    ((((a)) < 0)?(-((a))):((a)))
#define MAXN 1000001
#define MAXM 501
#define MOD 1000000007
using namespace std;
typedef  long long  LL;

bool isPrime(int n){
    for(int i = 2; i*i <= n; i++){
        if(n % i == 0)
            return false;
    }
    return true;
}
string intStr(int n){
	if(n == 0)
		return "0";
	string ans = "";
	while(n > 0){
		ans += ('0' + n % 10);
		n /= 10;

	}
	return ans;
}
bool isPalindrome(int n){
    string str = intStr(n);
	for(int i = 0; i < str.length()/2; i++){
		if(str[i] != str[str.length() - 1 - i])
			return false;
	}
	return true;
}
LL p[MAXN];
LL sp[MAXN];
int main() {
	sp[1] = 1;
	for(int i = 2; i < MAXN; i++){
		int pinc = 0;
		int spinc = 0;
        if(isPrime(i)){
            pinc = 1;
        }
        if(isPalindrome(i))
            spinc = 1;
        p[i] = p[i - 1] + pinc;
        sp[i] = sp[i - 1] + spinc;
	}
    LL n,m;
	cin >> n >> m;
    for(int i = MAXN -1; i >= 1; i--){
        if((LL)m * p[i] <= (LL) n * sp[i]){
            cout << i;
            return 0;
        }

    }
    cout << "Palindromic tree is better than splay tree";
    return 0;
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <complex>

using namespace std;

typedef pair<int, int> pii;
typedef long long LL;

/*
#ifdef LOCAL
template <typename T>
auto is_printable_impl(int) -> decltype(cout << declval<T &>(), std::true_type{});
template <typename T>
std::false_type is_printable_impl(...);
template <typename T>
using is_printable = decltype(is_printable_impl<T>(0));

template <typename Tuple, size_t N>
struct TuplePrinter;
struct Debug {
    template <typename T>
    typename enable_if<!is_printable<T>::value, Debug &>::type operator<<(
            const T &x) {
        int i = 0;
        for (auto it = begin(x); it != end(x); ++it)
            *this << "[" << i++ << " : " << *it << "] ";
        return *this;
    }
    template <typename T>
    typename enable_if<is_printable<T>::value, Debug &>::type operator<<(
            const T &x) {
        cout << x;
        return *this;
    }
    template <typename T1, typename T2> // pair-printer
    Debug &operator<<(const pair<T1, T2> &p) {
        *this << "{" << p.first << ", " << p.second << "}";
        return *this;
    }
    template <typename... Args>
    Debug &operator<<(const tuple<Args...> &t) {
        cout << "(";
        TuplePrinter<decltype(t), sizeof...(Args) - 1>::print(t);
        cout << ")";
        return *this;
    }
} debug;
template <typename Tuple, size_t N>
struct TuplePrinter {
    static void print(const Tuple &t) {
        TuplePrinter<Tuple, N - 1>::print(t);
        debug << ", " << get<N>(t);
    }
};
template <typename Tuple>
struct TuplePrinter<Tuple, 0> {
    static void print(const Tuple &t) {
        debug << get<0>(t);
    }
};
#define dbg(x) do { debug << #x << " -> " << (x) << '\n'; } while (0)
#else
#define dbg(x) do {} while (0)
#endif
*/

const int INF = 0x3f3f3f3f;
const LL INF64 = 0x3f3f3f3f3f3f3f3f;

const int N = 1e7 + 10;

int C[N]; // 该数的最小质因数
int prime[N], pn; // 素数表
void sieve(int size) {
    for (int i = 2; i < size; ++i) { //
        if (!C[i]) C[i] = prime[pn++] = i;
        for (int j = 0; i * prime[j] < size; ++j) {
            C[i * prime[j]] = prime[j];
            if (i % prime[j] == 0) break; // smallest prime factor of i is prime[j], so we need
        }
    }
}

bool is_palin(int n) {
    string s = to_string(n);
    for (int i = 0; i < s.size() / 2; ++i) if (s[i] != s[s.size() - i - 1]) return false;
    return true;
}
int cnt1[N], cnt2[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    sieve(N);
    for (int i = 1; i < N; ++i) {
        cnt1[i] = cnt1[i - 1] + (C[i] == i);
        cnt2[i] = cnt2[i - 1] + is_palin(i);
    }
    int ans = 0;
    int p, q;
    cin >> p >> q;
    for (int i = 1; i < N; ++i) {
        if (q * cnt1[i] <= p * cnt2[i]) ans = i;
    }
    cout << ans << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

bool isPalindrome(int n) {
	string s;
	while (n > 0) s += (n % 10 + '0'), n /= 10;
	for (int i = 0; i < s.size(); i++)
		if (s[i] != s[s.size() - 1 - i])
			return false;
	return true;
}

int main() {
	const int N = 505050;
	static int pi[N];
	vector<char> isPrime(N, true);

	for (int i = 2; i < N; i++) if (isPrime[i]) {
		pi[i] = 1;
		for (int j = i * 2; j < N; j += i) isPrime[j] = false;
	}

	static int rub[N];
	for (int i = 1; i < N; i++) rub[i] += isPalindrome(i);

	partial_sum(pi, pi + N, pi);
	partial_sum(rub, rub + N, rub);

	long long p, q;
	cin >> p >> q;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (q * pi[i] <= p * rub[i]) ans = i;
	}
	cout << ans << endl;
}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long const M=32767;
bool P(int n)
{
    if(n==2) return 1;
    if(n%2==0)return 0;
    for(int i=3; i*i<=n; ++i)
        if(n%i==0)return 0;
    return 1;
}
bool Pln(int n)
{
    string s=to_string((long long)n),t=s;
    reverse(t.begin(),t.end());
    return s==t;
}
long A[M][2];
void main()
{
    int p,q,pC=0,plnC=0; cin>>p>>q;
    bool f=1;
    for(int i=1; i<M;++i)
    {
        if(i>1&&P(i))++pC;
        if(Pln(i))++plnC;
        A[i][0]=pC;
        A[i][1]=plnC;
    }
    for(int i=M-1; i; --i)
    {
        if(A[i][0]*q<=A[i][1]*p)
        {
            f=0;
            cout<<i;
            break;
        }
    }
    if(f)cout<<"Palindromic tree is better than splay tree";
}

//
//  main.cpp
//  A. Primes or Palindromes?
//
//  Created by Dhruv Mullick on 10/08/15.
//  Copyright (c) 2015 Dhruv Mullick. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back
#define f first
#define s second
typedef pair<int,int> ii;
typedef pair<int,pair<int,int> > iii;

bool B[1000007];
int C[1000007];
int P[1000007];

bool palin(int x)
{
    int i,x1;
    x1=x;
    stack<int> S;
    queue<int> Q;
    while(x>0)
    {
        S.push(x%10);
        Q.push(x%10);
        x=x/10;
    }

    while(!S.empty())
    {
        if(Q.front()!=S.top())
            return false;
        Q.pop();
        S.pop();
    }
    return true;
}

int main(int argc, const char * argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int i,j;
    double p,q,A;
    B[1]=0;
    B[0]=0;

    cin>>p>>q;

    for(i=2;i<1000006;i++)
        B[i]=1;

    for(i=2;i<1000006;i++)
    {
        if(!B[i])
            continue;
        for(j=i*2;j<1000006;j+=i)
            B[j]=0;
    }

    for(i=2;i<1000006;i++)
        C[i]=C[i-1]+B[i];

//    for(i=0;i<1000006;i++)
//        if(C[i]!=C[i-1])
//            cout<<i<<" "<<"->"<<C[i]<<"\n";
//

    A=p/q;

    int m=0;

    for(i=1;i<1000006;i++)
    {
        P[i]=P[i-1]+palin(i);
        if(A*P[i]>=(double)C[i])
            m=i;
        if(A*P[i]<C[i]*0.9)
            break;

//        cout<<i<<"-->"<<A*P[i]<<" "<<C[i]<<"\n";

    }

    if(m!=0)
        cout<<m;
    else
        cout<<"Palindromic tree is better than splay tree";

    return 0;
}

/*
 * File:   main.cpp
 * Author: malek
 *
 * Created on September 15, 2015, 6:28 PM
 */

#include <bits/stdc++.h>

using namespace std;

/*
 *
 */
vector<int>primes;
bitset<10000010>bs;
void sieve(int n){
    bs.set();
    bs[0]=0;
    bs[1]=0;
    for(long long i=0;i<=n;i++){
        if(bs[i]){
            primes.push_back(i);
            for( long long j=i*i;j<=n;j+=i){
                bs[j]=0;
            }
        }
    }
}

map<int,int>m;
int pow1(int n) {
    int s = 1;
    while (n)s *= 10, n--;
    return s;
}

int palbefore(int nm) {
    vector<int>v;
    while(nm){
        v.push_back(nm%10);
        nm/=10;
    }
    if(v.empty())return 1;
    if(v.size()==1)return v[0]+1;
    int x = (v[v.size() - 1] - 1)*(pow1((v.size() - 1) / 2));
    if (v[0] >= v[v.size() - 1]) {
        int sum=1;
        for(int i=1;i<v.size()-1;i++){
            sum*=min(v[i],v[v.size()-i-1])+1;
        }
        return x+sum;
    }
    return x;
}
int rub(int i){
    return m.lower_bound(i/10)->second +palbefore(i);
}

int main() {

    int sum=0;
    m[0]=0;
    sieve(10000000);
    for(int i=9;i<10000000;i*=10,i+=9){
        sum+=palbefore(i);
        m[i]=sum;
    }
    int p,q;
    cin>>p>>q;
    int high=10000000;
    int low=0;
    while(high>low){
        int mid=high+low+1;
        mid/=2;
//        cout<<low<<" "<<mid<<" "<<high<<endl;
        int mid2=upper_bound(primes.begin(),primes.end(),mid)-primes.begin();
        if(p*(rub(mid)-1)>=q*(mid2))
            low=mid;
        else
            high=mid-1;

    }
    cout<<high<<endl;
//    cout<<rub(40)<<endl<<upper_bound(primes.begin(),primes.end(),40)-primes.begin();

    return 0;
}

#include<bits/stdc++.h>
#define ll int
#define dbg(x) cerr<< #x<<" ="<<x<<endl;
#define dbg2(x,y) cerr<< #x<<" ="<<x<<" "<<#y<<" ="<<y<<endl;
using namespace std;
ll pm[10001],pl[10001],a[10001];
void prime()
{
    ll i,j;
    for(i=2;i<=sqrt(10000);i++)
    {
        if(a[i]==0)
            for(j=i*i;j<=10000;j=j+i)
                a[j]=1;
    }
    for(i=2;i<=10000;i++)
    {
        if(a[i]==0)
            pm[i]=pm[i-1]+1;
        else
        {
            pm[i]=pm[i-1];
            a[i]=0;
        }
    }
}
void palin()
{
    ll i,j,k;
    string str,s1;
    char ch;
    for(i=1;i<10;i++)
    {
        pl[i]=1;
    }
    for(i=10;i<=10000;i++)
    {
        j=i;
        while(j>0)
        {
            k=j%10;
            ch=k+'0';
            str=ch+str;
            j=j/10;
        }
        s1=str;
        reverse(str.begin(),str.end());
        if(s1==str)
            pl[i]=1;
        str.clear();
    }
}
int main()
{
    prime();
    palin();
    ll i,j,k,l,n,m,t,p,ans=0,temp=0,q;
    for(i=1;i<=10000;i++)
       pl[i]=pl[i-1]+pl[i];
    cin>>p>>q;
//    for(i=1;i<=60;i++)
//    {
//        cout<<i<<"  "<<pm[i]<<" & "<<pl[i]<<endl;
//    }
    ans=0;
    for(i=1;i<=1000;i++)
    {
        pm[i]*=q;
        pl[i]*=p;
        if(pm[i]<=pl[i])
            ans=i;
        else
        {
            if(ans!=0)
                break;
        }
    }
    if(ans==0)
    {
        cout<<"Palindromic tree is better than splay tree";
    }
    else
        cout<<ans;
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

const int maxn = 1000005;
// const long long mod = 1e9 + 7;

int a, b;

bool primes[maxn];

int main() {
	cin >> a >> b;
	vector <int> primes_list;
	vector <int> palindrome_list;
	for (int i = 2; i < maxn; ++i) {
		primes[i] = 1;
	}
	for (int i = 2; i < maxn; ++i) {
		if (primes[i]) {
			for (int j = 2; j * i < maxn; ++j) {
				primes[i * j] = 0;
			}
		}
	}
	for (int i = 2; i < maxn; ++i) {
		if (primes[i]) {
			primes_list.push_back(i);
		}
	}
	for (int i = 1; i < maxn; ++i) {
		string s = to_string((long long)i);
		bool ok = true;
		for (int j = 0; j < s.size(); ++j) {
			if (s[j] != s[s.size() - j - 1]) {
				ok = false;
			}
		}
		if (ok) {
			palindrome_list.push_back(i);
		}
	}
	int maxi = -1;
	for (int i = 0; i < maxn; ++i) {
		std::vector<int>::iterator up;
		up = upper_bound (primes_list.begin(), primes_list.end(), i);
		int pi_n = up - primes_list.begin();
		up = upper_bound (palindrome_list.begin(), palindrome_list.end(), i);
		int rub_n = up - palindrome_list.begin();
		if (pi_n * b <= a * rub_n) {
			maxi = max(maxi, i);
		}
	}
	if (maxi == -1) {
		cout << "Palindromic tree is better than splay tree";
	} else {
		cout << maxi;
	}
}

#include<bits/stdc++.h>
#define ll int
using namespace std;
const int maxN=3e6+100;
ll p[maxN];
void gharbal(){
    p[1]=1;
    for(ll i=2;i<maxN;i++){
        if(!p[i]){
            ll q=i+i;
            while(q<maxN){
                p[q]=1;
                q+=i;
            }
        }
    }
}
ll palin(ll n){
    ll t=0;
    while(n){
        t*=10;
        t+=n%10;
        n/=10;
    }
    return t;
}
int main(){
    gharbal();
    ll a,q,mx= -1,prime=0,palind=0;
    cin>>a>>q;
    for(ll i=1;i<=maxN;i++){
        if(!p[i])
            prime++;
        if(palin(i)==i)
            palind++;
        if(prime*q <= palind*a)
            mx=i;
        //if(i==2530||i==30)

        //cout<<i<<" "<<prime<<" "<<palind<<endl;
           // cout<<i<<"   "<<prime<<" "<<palind<<endl;
    }
    cout<<mx<<endl;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <cassert>

using namespace std;

typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second

const int maxn = 10000000;
int p[maxn], q[maxn];

int main() {
    #ifdef _TEST_
    freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    #endif
    int a, b; cin >> a >> b;
    for (int i = 2; i < maxn; i ++) {
        if (p[i]) continue;
        for (int j = i + i; j < maxn; j += i)
            p[j] = 1;
    }
    for (int i = 2; i < maxn; i ++) {
        if (p[i] == 0) p[i] = p[i - 1] + 1;
        else p[i] = p[i - 1];
    }
    for (int i = 0; i < 10; i ++)
        q[i] = q[i * 10 + i] = 1;
    for (int i = 100; i < maxn; i ++) {
        int t = i, m = 1;
        //while (t % 10 == 0) t /= 10;
        //int r = t;
        while (t >= 10) t /= 10, m *= 10;
        if (t != i % 10) continue;
        q[i] = q[(i - t * m) / 10];
    }
    for (int i = 2; i < maxn; i ++)
        q[i] += q[i - 1];
    //cout << q[maxn - 1] << ' ' << p[maxn - 1] << endl;
    //cout << p[173] * 1.0 / q[173] << endl;
    for (int i = maxn - 1; i >= 1; i --) {
        if (p[i] * b <= q[i] * a) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "Palindromic tree is better than splay tree" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> State;

int dp[1000001];
vector<int> primes;
#define MAX 500000
void sieve()
{
    for (int i = 2; i < MAX; i++) dp[i] = 1;
    for (int i = 2; i < MAX; i++)
        if (dp[i])
            for (int j = 2*i; j < MAX; j += i)
                dp[j] = false;
    for (int i = 2; i < MAX; i++)
        if (dp[i])
            primes.push_back(i);
}

int pi(int n)
{
    return (upper_bound(primes.begin(),primes.end(),n) - primes.begin());
}

bool pal(string s)
{
    for (int i = 0; i < s.size()/2; i++)
        if (s[i] != s[s.size()-1-i]) return false;
    return true;
}

int memo[1000001];
int rub(int n)
{
    memo[0] = 0;
    for (int i = 1; i <= n; i++)
        if (pal(to_string(i))) memo[i] = memo[i-1] + 1;
        else memo[i] = memo[i-1];
}

int main()
{
    sieve();
    rub(500000);
    long long P,Q; cin >> P >> Q;
    int ans = -1;
    for (int i = 1; i <= 500000; i++)
        if (Q*pi(i)<=P*memo[i])
            ans = i;

    if (ans == -1) cout << "Palindromic tree is better than splay tree" << endl;
    else cout << ans << endl;
}

#include <iostream>
#include <bits/stdc++.h>
#define upperlimit 20000005
#define segment 2000
using namespace std;
bool primes[upperlimit+1];
int primecount[upperlimit+1];
int palindromecount[upperlimit+1];
bool ispalindrome(int num)
{
	int temp=num,m=0;
	while(temp>0){
		m = m*10 + temp%10;
		temp/=10;
	}
	return (num==m);
}
int main() {
	// your code goes here
	int i,j,k,p,q;
	for(i=2;i*i<upperlimit;i++)if(!primes[i])for(j=i*i;j<=upperlimit;j+=i)primes[j]=true;
	k=0;
	palindromecount[1]=1;
	for(i=2;i<=upperlimit;i++){
		primecount[i]=primecount[i-1];
		if(!primes[i])primecount[i]++;
		palindromecount[i]=palindromecount[i-1];
		if(ispalindrome(i))palindromecount[i]++;
	}
	cin>>p>>q;
	bool f=false;
	for(i=upperlimit;i>=1;i-=segment){
		if(q*primecount[i]<=p*palindromecount[i])break;
	}
	for(j=i+segment;j>=1;j--){
		if(q*primecount[j]<=p*palindromecount[j]){f=true;break;}
	}
	if(!f){
		for(j=upperlimit;j>=1;j--){
		if(q*primecount[j]<=p*palindromecount[j]){f=true;break;}
	}
	}
	if(f)cout<<j;
	else cout<<"Palindromic tree is better than splay tree";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll   long long
//#define max 706000
#define gc getchar_unlocked
#define pc putchar_unlocked
//inline void get(int *p){register  int n=0,sign=1,a=gc();while(a<'0'||a>'9'){ if(a=='-'){sign=-1;a=gc();break;} a=gc();}while(a>='0' && a<='9'){n=(n<<1)+(n<<3)+a-'0';a=gc();}*p=n*sign;}

//inline void put(int n){char d[10];int i=0;if(n<0){pc('-');n=-n;}do{d[i++]=n%10+'0';n=n/10;}while(n);while(i)pc(d[--i]);pc('\n');}
#define modu 1000000007
int modular_pow(int  base, int  exponent)
{
     int result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base);
        exponent = exponent >> 1;
        base = (base * base);
    }
    return result;
}

 int gcd(ll int a,ll int b){
    if(b==0)
    return a;//gcd
    else return gcd(b,a%b);
 }

bool chek(int x){
    return (x&&!(x&(x-1)));// power of 2
}
int a[4000200];
vector<int>pr;
int p1[4000200];
int palin[4000200];
bool check(int n){
    vector<int >pp;
    while(n!=0){
        pp.push_back(n%10);
        n/=10;

    }
    for(int u=1;u<=(pp.size()/2);u++){
        if(pp[u-1]!=pp[pp.size()-u]){
            return false;
        }

    }
    pp.clear();
    return true;
}

void pali(){
    for(int u=1;u<=4000000;u++){
        if(check(u)){
            palin[u]=palin[u-1]+1;

        }
        else palin[u]=palin[u-1];

    }
//  for(int u=1;u<100;u++)
//  cout<<palin[u]<<" ";

}

void seive(){
    for(int u=2;u<=4000000;u+=2)
    a[u]=1;
    for(int u=3;u<=4000000;u+=3)
    a[u]=1;
    a[2]=0;
    a[3]=0;
    for(int u=5;u*u<=4000000;u+=2){
        if(a[u]==0){

        for(int j=2*u;j<=4000000;j+=u)
        a[j]=1;}

    }
    p1[1]=0;
    p1[2]=1;
    p1[3]=2;
    for(int u=4;u<=4000000;u++){
        if(a[u]==0)
        p1[u]=p1[u-1]+1;
        else p1[u]=p1[u-1];

    }
//  for(int u=1;u<=100;u++)
//  cout<<p1[u]<<" ";
}
int main(){
    seive();
    pali();
    int n,m;
      scanf("%d",&n);scanf("%d",&m);
    int maxx=-1;
    int s=n;
    int k=m;
    n/=gcd(s,k);
    m/=gcd(s,k);
   // cout<<p1[10000]<<" "<< palin[10000]<<endl;
    for(int u=1;u<=4000000;u++){
        if(palin[u]*n >=p1[u]*m){
        maxx=u;
        }

    //  maxx=u;break;}

    }
    printf("%d\n",maxx);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define sz(x) ((int) (x).size())
#define pB push_back
#define X first
#define Y second
#define pii pair<int, int>

#define MAX 10000000
int prime_count[MAX];
int pal_count[MAX];
bool isNotPrime[MAX];

void seive(int n) {
	isNotPrime[0] = isNotPrime[1] = true;
	for (int i = 2; i * 1L * i <= n; i++) if (!isNotPrime[i]) // i : prime
			for (int j = i * i; j <= n; j += i)
				isNotPrime[j] = true;
}

int getRev(int n) {
	int ret = 0;
	while (n != 0) {
		ret = ret * 10 + n % 10;
		n /= 10;
	}
	return ret;
}

bool isPal(int n) {
	int rev = getRev(n);
	return rev == n;
}

int main() {
	// ios_base::sync_with_stdio(false); cin.tie(0);
	int p, q;
	cin >> p >> q;
	int gcd = __gcd(p, q);
	p /= gcd; q /= gcd;

	seive(MAX - 1);
	for (int i = 1; i < MAX; i++) {
		pal_count[i] = pal_count[i - 1];
		if (isPal(i)) pal_count[i]++;
		prime_count[i] = prime_count[i - 1] + (isNotPrime[i] ? 0 : 1);
	}

	// for (int i = 0; i < 20; i++) {
	// 	cout << pal_count[i] << ' ' << prime_count[i] << endl;
	// }

	int s = 1; int e = MAX;
	while (e - s > 1) {
		int mid = (e + s) >> 1;
		if (q * 1L * prime_count[mid] <= p * 1L * pal_count[mid])
			s = mid;
		else
			e = mid;
	}
	cout << s << endl;
	return 0;
}

/**
*	 built in Contest Parser [Version 1.02]
**/

#include<bits/stdc++.h>
#define ll long long
#define N 1000006
using namespace std;
int spf[N];
void sieve()
{
    spf[0] = 1;
    for(int i=2;i*i<N;i++)
        if(!spf[i])
        for(int j=i;j<N;j+=i)
        if(!spf[j])
        spf[j] = i;
    for(int i=3;i<N;i+=2)
        if(!spf[i])
            spf[i] = i;
}
bool check(int num)
{
    if(!num)
        return false;
    string str = to_string(num);
    for(int i=0;i<str.size()/2;i++)
        if(str[i]!=str[str.size()-1-i])
            return false;
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sieve();
    int p,q,ans = -1,prime=0,palindrome=0;
    cin>>p>>q;
    for(int i=0;i<N;i++)
    {
        if(spf[i]==i)
            prime++;
        if(check(i))
            palindrome++;
        if(q*prime<=palindrome*p)
            ans = i;
    }
    if(~ans)
        cout<<ans;
    else
        cout<<"Palindromic tree is better than splay tree";
    return 0;
}

#include<stdio.h>
#include<string.h>
#define maxn 1000000
int a[maxn+10],b[maxn+10],c[maxn+10],d[maxn+10];
bool judge(int x){
    int i,j,len=0,tmp[10];
    while(x){
        tmp[++len]=x%10;
        x/=10;
    }
    for(i=1,j=len;i<=len/2;i++,j--){
        if(tmp[i]!=tmp[j]) return false;
    }
    return true;
}
int main(){
    memset(a,0,sizeof(a));
    a[1]=1;
    for(int i=2;i<=maxn;i++){
        if(!a[i]){
            int t=2;
            while(i*t<=maxn){
                a[i*t]=1;
                t++;
            }
        }
    }
    b[0]=-1;
    b[1]=0;
    for(int i=2;i<=maxn;i++){
        if(a[i]==0) b[i]=b[i-1]+1;
        else b[i]=b[i-1];
    }
    d[0]=0;
    for(int i=1;i<=9;i++) d[i]=d[i-1]+1;
    memset(c,0,sizeof(c));
    for(int i=10;i<=maxn;i++){
        if(judge(i)) c[i]=1;
    }
    for(int i=10;i<=maxn;i++){
        if(c[i]==1) d[i]=d[i-1]+1;
        else d[i]=d[i-1];
    }
    int p,q,i,flag=0;
    scanf("%d%d",&p,&q);
    for( i=1;i<=maxn;i++){
       // printf("%d  %d %d\n",i,b[i],d[i]);
        if(q*b[i]>p*d[i]) {
            flag=1;
            break;
        }
    }
    if(flag==1){
        printf("%d\n",i-1);
    }
    else printf("Palindromic tree is better than splay tree\n");

    return 0;
}

#include<bits/stdc++.h>
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define si(x) scanf("%d",&x)
#define sll(x) scanf("%lld",&x)
#define ss(x) scanf("%s",x)
#define pi(x) printf("%d\n",x)
#define pll(x) printf("%lld\n",x)
#define ps(x) printf("%s\n",ch)
#define INF 2000000000
#define ll long long
#define mp make_pair
#define pb push_back
#define fr first
#define se second
using namespace std;
int pr[1000069],palin[1000069]={};
void seive()
{
    pr[0]=0,pr[1]=0;
    for(int i=2;i*i<=1000005;i++)
        if(pr[i]==1)
        {
            for(int j=i*i;j<=1000005;j+=i)
                pr[j]=0;
        }
    FOR(i,1,1000005)
        pr[i]=pr[i-1]+pr[i];
}
void pali()
{
    FOR(i,1,1000069)
    {
        int t=i,d=0;
        while(t!=0)
            d=d*10+t%10,t/=10;
        if(i==d)
            palin[i]=1;
    }
    FOR(i,1,1000005)
        palin[i]=palin[i-1]+palin[i];
}
int main()
{
    double p,q;
    FOR(i,2,1000006)
        pr[i]=1;
    seive();
    pali();
    cin>>p>>q;
    int i=100000,ans=-1;
   // FOR(i,0,105)
    //  cout<<pr[i]<<" "<<palin[i]<<endl;
    while(1)
    {
        if(pr[i]<=(palin[i]*1.0*(p/q)))
        {
            ans=i;
            break;
        }
        i--;
    }
    if(ans==-1)
    cout<<"Palindromic tree is better than splay tree"<<endl;
    else
    cout<<ans<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define Endl '\n'
typedef long long int lli;
typedef pair<int, int> ii;
void solve();
int main(int argc, char const *argv[]){
   ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}

bool prime(int a){
  if(a==1)
    return false;
  for(int i=2;i<=sqrt(a);i++){
    if(a%i == 0)
      return false;
  }
  return true;
}
bool palindrome(int a){
  string str = to_string(a);
  string t = str;
  reverse(t.begin(), t.end());
  return str ==t;
}
void solve(){
  int p, q;
  cin>>p>>q;
    vector<int> a(420001);
    vector<int> b(420001);
    a[0] = 0;
    b[0] = 0;
    for(int i=1;i<=420000;i++){
      a[i] = a[i-1] + prime(i);
      b[i] = b[i-1] + palindrome(i);
    }

    for(int i=420000;i>=1;i--){
      if(p*b[i]>=q*a[i]){
        cout<<i<<endl;
        return;
      }
    }

    cout<<"Palindromic tree is better than splay tree"<<endl;
    return;
}

#include <cstdio>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
const int MAXX = 1e6+10;

bool not_prime[MAXX];
vector<int> ps;
int phi[MAXX];
int rub[MAXX];

char s[10]={};
int is_pal(int n) {
	sprintf(s, "%d", n);
	int sl = strlen(s);
	int L = 0, R = sl-1;
	while(L<R) {
		if(s[L]!=s[R]) return 0;
		L++, R--;
	}
	return 1;
}

int main() {
	int p, q;
	scanf("%d %d", &p, &q);
	// q*phi(n) <= p*rub(n)
	for(int i=2;i*i<MAXX;i++){
		if(not_prime[i]) continue;

		for(int j=i*i;j<MAXX;j+=i)
			not_prime[j] = true;
	}

	for(int i=2;i<MAXX;i++)
		if(!not_prime[i])
			ps.push_back(i);

	for(int i=1;i<MAXX;i++) {
		phi[i] = upper_bound(ps.begin(), ps.end(), i)-ps.begin();
		rub[i] = rub[i-1] + is_pal(i);
	}

	int ans = -1;
	for(int i=MAXX-1;i>0;i--){
		if((ll)q*phi[i] <= (ll)p*rub[i]) {
			ans = i;
			break;
		}
		// printf("%d: %d %d\n", i, phi[i], rub[i]);
	}

	if(ans==-1) {
		puts("Palindromic tree is better than splay tree");
		return 0;
	}

	printf("%d", ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i,j,k) for(ll i=j;i<ll(k);i++)
#define wch(x) cout<<(#x)<<" "<<x<<endl
#define fio ios::sync_with_stdio(0);cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a,0,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi pair<int,int>
#define vi vector<int>
#define sec second
#define fst first
#define ti tuple<int,int,int>
#define mt(a,b,c) make_tuple(a,b,c)
#define c2(n)   (1LL*((n)*1LL*((n)-1))/2)
#define vv(type) vector<vector<type>>
//#define clc(xj,yj,xf,yf) (abs(xj-xf)+abs(yf-yj))
const int mn=INT_MIN;
const int mx=INT_MAX;
const int mod=998244353;
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz=(1e7)+10;
vector<bool> prime(sz,1);
vector<bool> pal(sz,1);
int curr=0;

void clc(string s)
{int n=s.size();
 f(i,0,n/2) {if(s[i]!=s[n-1-i]) {pal[curr]=0;break;}}
    }
int main()
{fio;
f(i,2,sz) {
    if(prime[i]) {
        for(ll j=i*i;j<sz;j+=i) {
            prime[j]=0;
            }
        }
    }
f(i,1,sz) {int a=i;string s;
    while(a) s+=char((a%10)+'0'),a/=10;
    curr=i;
    clc(s);
    }
prime[0]=0;
prime[1]=0;
int pc=0,plc=0;
int p,q,ans=mn;
cin>>p>>q;
f(i,1,sz) {
    if(pal[i]) plc++;
    if(prime[i]) pc++;
    if(q*pc<=p*plc) ans=max(1LL*ans,i);
    }
if(ans==mn) cout<<"Palindromic tree is better than splay tree";
else cout<<ans;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll OO =(ll)1e15;

vector <ll> v1;
map<char,ll>ma;
int pri[10000000];

void sieve(ll n)
{
   int i,c=0,j;
    pri[0]=1,pri[1]=1;
     for (int i = 2; i * i <= n; i++)
        {
        if (!pri[i])
          {
            for (int j = i * i; j <= n; j += i)
            {
              pri[j] = true;
            }
          }
        }

}

bool f(ll n)
{
      string s,x;
      stringstream ss;
      ss << n;
      s = ss.str();
      x=s;
      reverse(s.begin(), s.end());
      if(x==s)
      {
          return true;
      }
    return false ;

}

int main()
{
    ll p,q,pr=0,pa=0,t=0;
    cin>>p>>q;
    sieve(420000);

    for (ll i = 1; i <= 420000; i++)
    {
		if (pri[i]==0)
		 {
		     pr++;
		 }
		if (f(i)==1)
		 {
		     pa++;
		 }
		if (pa * p >= pr * q)
		 {
		     t = i;
		 }
	}

  cout<<t;

}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cmath>
#include <climits>
#include <utility>
#include <fstream>
#include <memory>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
#define debug(v) cout << "Variable is " << v << endl;
#define PA(A,i,n) for(int i = 0; i < n; i++) cout << A[i] << " "; cout << endl;
#define FOR(a, b, n) for(int (a) = (b); (a) < (n); a++)
#define LL long long
#define ALL(v) v.begin(),v.end()
#define ZERO(v) memset(v, 0, sizeof v)
#define NEG(v)  memset(v, -1, sizeof v)
#define PB push_back
#define MP make_pair
#define PI 3.141592653589793
#define MOD 1000000007
inline double min(double a , double b) {if(a < b)return a; return b;}
inline double max(double a , double b) {if(a < b)return b; return a;}
const int  N = 1179858;
int p, q;
vector<int> primes;
LL dp1[N];
LL dp2[N];
vector<int> para;
void generate2()
{
    int flag[N + 10];
    ZERO(flag);
    FOR(i, 1, N + 1)
    {
        int nn = i;
        int digit = 0;
        while(nn)
        {
            digit++;
            nn /= 10;
        }
        nn = i;
        bool f = true;
        while(digit > 1 && nn > 0)
        {
            int one = nn % 10;
            int base = pow(10,digit - 1);
            if(nn / base != one)
            {
                f = false;
                break;
            }
            nn -= one;
            nn -= base * one;
            nn /= 10;
            digit -= 2;
        }
        if(f)
        {
            para.push_back(i);
        }
        dp2[i] = para.size();
    }
}
void generate()
{
    int flag[N + 10];
    ZERO(flag);
    for(int i = 2; i <= N; i++)
    {
        if(flag[i] == false)
        {
            primes.PB(i);
        }
        for(int j = 0; j < primes.size() && i * primes[j] <= N;j++)
        {
            flag[i * primes[j] ] = 1;
            if(i % primes[j] == 0)
                break;
        }
        dp1[i] = primes.size();
    }
}

int main(){
    cin >> p >> q;
    generate();
    generate2();
    int i = 1;
    int res = -1;
    for(i = 1; i <= N; i++)
    {
        LL first = dp1[i] * q;
        LL second = p * dp2[i];
        if(first <= second)
        {
            res = i;
        }
    }
    if(res == -1)
        cout << "Palindromic tree is better than splay tree" << endl;
    else
        cout << res << endl;
}

#include <bits/stdc++.h>
#define _start ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
bool *prime,recount=1,*pali;
int p,q,pi=0,rub=0,sp=1,sol=-1;
bool seive_prime(int st,int n)
{int k=n-st;
int mo;
if(n<=st)return 0;
    for(int i=2;i*i<=n;i++)
      {

        if(prime[i])
        { mo=(st-st%i+i);
            for(int j=max(i*i,mo);j<=n;j+=i)
            {if(prime[j]==1)k--;prime[j]=0;}

        }
      }
       pi+=k;
        return 0;
}
bool  pali_incre(int *number,int high , int low,int st)
{int t=1;int incval=0;
bool pass;
    for(int i=0;i<=high;i++)
    {
        if(i==low)
            incval+=t;
        if(i==high)
        {
            incval+=t;
            break;
        }
        t*=10;
    }
    //=t+pow(10,high);
    int gain=0;
    if(high==low)incval=incval>>1;
    for(int i=st;i<=9;i++)
    {
            if(*number>20)
                pass=1;
            else
                pass=0;
            if(high-low>1)
            {

                if(pali_incre(number,high-1,low+1,0))return 1;
            }
            else{   rub++;
                    fill(prime+st+1,prime+*number+1,1);
                    seive_prime(sp,*number);
                    if(q*pi<=rub*p)recount=1;
                    if(q*pi>rub*p&&recount){ sol=*number;recount=0;}
                    if((p>=q||pass)&&sol>-1)

                        return 1;
                    sp=max(sp,*number);
                }
            *number+=incval;
            gain+=incval;
    }

    *number-=gain;
    return 0;
    }
int main()
{
    _start
    prime=(bool*)malloc(10*sizeof(bool));
    scanf("%d%d",&p,&q);
    int l,h=1;
    int n=1;
int endd=9,nend=9;
    while(1)
    {

        if(pali_incre(&n,h-1,0,1)){ n=sol; break;}
        h++;
        n=1;
        int i;
        for( i=0;i<h-1;i++)
            {n*=10;nend*=n+9;}

        prime=(bool*)realloc(prime,10*n*sizeof(bool));
        pali=(bool*)realloc(pali,10*n*sizeof(bool));

        n+=1;
    }
rub--;
    for(int i=n;i>sp-1;i--)
    {
        if(prime[i])pi--;
        if(q*pi<=rub*p)
        {n=i-1;break;}
    }
    if(n<=11)
        n--;
    printf("%d",n);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll OO =(ll)1e15;

vector <ll> v1;
map<char,ll>ma;
int pal[1000000];
int pri[1000000];

void sieve(ll n)
{
   int i,c=0,j;
    pri[0]=1,pri[1]=1;
     for (int i = 2; i * i <= n; i++)
        {
        if (!pri[i])
          {
            for (int j = i * i; j <= n; j += i)
            {
              pri[j] = true;
            }
          }
        }

}

ll f(ll n)
{
    int c=0;
    for(int i=1;i<=n;i++)
    {
      string s,x;
      stringstream ss;
      ss << i;
      s = ss.str();
      x=s;
      reverse(s.begin(), s.end());
      if(x==s)
      {
          pal[i]=1;
      }
    }

}

int main()
{
    int p,q,pr=0,pa=0,t=0;
    cin>>p>>q;
    sieve(420000);
    f(420000);

    for (int i = 1; i <= 420000; i++)
    {
		if (pri[i]==0)
		 {
		     pr++;
		 }
		if (pal[i]==1)
		 {
		     pa++;
		 }
		if (pa * p >= pr * q)
		 {
		     t = i;
		 }
	}
 if(t!=0)
  cout<<t;
  else
    cout<<"Palindromic tree is better than splay tree";
}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
long const M=4000000;
bool P(int n)
{
    if(n==2) return 1;
    if(n%2==0)return 0;
    for(int i=3; i*i<=n; ++i)
        if(n%i==0)return 0;
    return 1;
}
bool Pln(int n)
{
    string s=to_string((long long)n),t=s;
    reverse(t.begin(),t.end());
    return s==t;
}
long A[M][2];
void main()
{
    int p,q,pC=0,plnC=0; cin>>p>>q;
    bool f=1;
    for(int i=1; i<M;++i)
    {
        if(i>1&&P(i))++pC;
        if(Pln(i))++plnC;
        A[i][0]=pC;
        A[i][1]=plnC;
    }
    for(int i=M-1; i; --i)
    {
        if(A[i][0]*q<=A[i][1]*p)
        {
            f=0;
            cout<<i;
            break;
        }
    }
    if(f)cout<<"Palindromic tree is better than splay tree";
}

/*
 *    11582 - Colossal Fibonacci Numbers
 */
#include<fstream>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<list>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<deque>
#include<ctime>
#include<complex>
#include<bitset>
#include<time.h>

using namespace std;
#define PB push_back
#define LL long long
#define MP make_pair
typedef unsigned long long ULL;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define DBG 0

#define fori(i,a,b) for(int i = (a); i < (b); i++)
#define forie(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i > (b); i--)
#define forde(i,a,b) for(int i = (a); i >= (b); i--)
#define forls(i,a,b,n) for(int i = (a); i != (b); i = n[i])
#define mset(a,v) memset(a, v, sizeof(a))
#define mcpy(a,b) memcpy(a, b, sizeof(a))

#define dout  DBG && cerr << __LINE__ << " >>| "
#define checkv(x) dout << #x"=" << (x) << " | "<<endl
#define checka(array,a,b) if(DBG) { \
dout << #array"[] | " << endl; \
forie(i, a, b) cerr << "[" << i << "]=" << array[i] << " |" << ((i - (a)+1) % 5 ? " " : "\n"); \
if (((b)-(a)+1) % 5) cerr << endl; \
}

#define redata(T, x) T x; cin >> x
#define MIN_LD -2147483648
#define MAX_LD  2147483647
#define MIN_LLD -9223372036854775808
#define MAX_LLD  9223372036854775807
#define MAX_INF 18446744073709551615
const int INF = 0x7fffffff;//use double for addition
inline int  reint() { int d; scanf("%d", &d); return d; }
inline long relong() { long l; scanf("%ld", &l); return l; }
inline char rechar() { scanf(" "); return getchar(); }
inline double redouble() { double d; scanf("%lf", &d); return d; }
inline string restring() { string s; cin >> s; return s; }

typedef set<int> Set;
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
//set_union(ALL(x1),ALL(x2),INS(x)),set_intersection

const int maxn = 1000000+10;

bool is[maxn]; int prm[maxn];
int getprm(int n){
    if (n<=1) return 0;
    n++;
    int i, j, k = 0;
    int s, e = (int)(sqrt(0.0 + n) + 1);
    memset(is, 1, sizeof(is));
    prm[k++] = 2; is[0] = is[1] = 0;
    for (i = 4; i < n; i += 2) is[i] = 0;
    for (i = 3; i < e; i += 2) if (is[i]) {
        prm[k++] = i;
        for (s = i*2, j= i*i;j<n;j+=s) is[j] = 0;
    }
    for ( ; i < n; i += 2) if (is[i]) prm[k++] = i;
    return k; //number of primes
}

int len(int a){
    int ans = 0;
    while(a>0){
        a/=10;
        ans++;
    }
    return ans;
}
int pal[1000];
int getpaldigit(int d){
    int& ans = pal[d];
    if (ans > 0) return ans;
    if (d == 1) {ans = 9;return ans;}
    else if (d == 2) {ans = 9; return ans;}
    else if(d%2 == 1) ans = 10*getpaldigit(d-1);
    else ans = 10*getpaldigit(d-2);
    return ans;
}
bool ispal(int a){
    int b = a;
    int rev = 0;
    while(a>0){
        int dig = a%10;
        rev = rev*10 + dig;
        a /= 10;
    }
    return b==rev;
}
int rev(int a){
    int r = 0;
    while(a>0){
        int dig = a%10;
        r = r*10 + dig;
        a /= 10;
    }
    return r;
}
int getpal(int n){
    int l = len(n);
    //first calculate the number of pals with digits less than l
    int ans = 0;
    memset(pal,0,sizeof(pal));
    fori(i,1,l){
        ans += getpaldigit(i);
    }//cout << l << endl;
    //then calculate the number of pals with the same digits as n
    int l1 = l/2;
    int h1 = n/pow(10,l1);
    ans += h1-pow(10,len(h1)-1);
    //if (ispal(n)) ans++;
    int h2 = n-h1*pow(10,l1);
    if(len(h1)==len(h2)){
        if(rev(h1)<=h2) ans++;
    }
    else{
        h1 = h1/10;
        if(rev(h1)<=h2) ans++;
    }
    return ans;

}
int p,q;
int main(void){
    cin >> p >> q;
    int i = 1;
    int maxi = 0;
    while(i<=1000){
        if(getpal(i)*p>=getprm(i)*q) {maxi = i;}
        i++;
    }
    //cout << getpal(172)*p << ' ' << getprm(172)*q<<endl;
    if (maxi) cout << maxi << endl;
    else cout << "Palindromic tree is better than splay tree" << endl;
    return 0;
}

#include <bits/stdc++.h>
#define N 2000001
using namespace std;
long long n, a[N], c[N], pp;
double b[N];
double p, q;
int palin(long long p)
{
    int stt = 0, e[100];
    while (p > 0)
    {
        stt++;
        e[stt] = p % 10;
        p = p / 10;
    }
    for (int i = 1; i <= stt / 2; i++)
        if (e[i] != e[stt - i + 1]) return 0;
    return 1;
}
int main()
{
    c[1] = 2; c[2] = 3; pp = 2;
    a[2] = 1; a[3] = 1;
    for (int i = 4; i <= 2000000; i++) {
        long t = 0;
        for (int j = 1; j <= pp; j++) {
            if (i % c[j] == 0) {
                t = 1;
                break;
            }
            if (c[j] > sqrt(i)) break;
        }
        if (t == 0) {
            pp++;
            c[pp] = i;
            a[i] = 1;
        }
    }
    for (int i = 2; i <= 2000000; i++) b[i] = b[i - 1] + a[i];
    long long kq = 0;
    double k = 0;
    cin >> p >> q;
    for (int i = 1; i <= 2000000; i++) {
        if (palin(i) == 1) k++;
        double kk = b[i];
        if ( p / q - kk / k >= 0) kq = i;
        //cout << i << " " <<  kk << " " << k << " " << kk/k - p/q << "\n";
    }
    if (kq == 0) cout << "Palindromic tree is better than splay tree";
        else cout << kq;
}
///CTKB1997

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include<assert.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>

#include <cstring>
#include <stdint.h>
#include <unistd.h>
using namespace std;
#define LL long long
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define pii pair<LL,LL>
#define rep(i,a,b) for(LL i=a;i<=b;++i)
#define ld double
#define tr(n) cin>>n
#define tr2(n,m) cin>>n>>m
#define tr3(a,b,c) cin>>a>>b>>c
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vii vector<pii>
#define vii vector<pii>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define Si set<LL>
#define SLL set<LL>
#define SpLL set<pLL>
#define Sii set<pii>

#define MOD 1000000007
#define NM 100005
#define LNM 20

vector<long long> primev;//stores the prime
void atkin()
{
    int limit = 1000001;
 int root = ceil(sqrt(limit));
 bool sieve[limit];
 int primes[(limit/2)+1];
 int insert = 2;
 primes[0] = 2;
 primes[1] = 3;
 for (int z = 0; z < limit; z++) sieve[z] = false;
 for (int x = 1; x <= root; x++)
 {
 for (int y = 1; y <= root; y++)
 {

 int n = (4*x*x)+(y*y);
 if (n <= limit && (n % 12 == 1 || n % 12 == 5)) sieve[n] ^= true;
 n = (3*x*x)+(y*y);
 if (n <= limit && n % 12 == 7) sieve[n] ^= true;
 n = (3*x*x)-(y*y);
 if (x > y && n <= limit && n % 12 == 11) sieve[n] ^= true;
 }
 }

 for (int r = 5; r <= root; r++) if (sieve[r]) for (int i = r*r; i < limit; i += r*r) sieve[i] = false;

 for (int a = 5; a < limit; a++)
 {
 if (sieve[a])
 {
 primes[insert] = a;
 insert++;
 }
 }

 for (int a = 0; a < insert; a++)primev.push_back(primes[a]);
 //for(int i=0;i<primev.size();++i)cout<<primev[i]<<endl;

}

LL dp1[1000005];
LL dp2[1000005];

int pp(LL x)
{
  string s="";
  while(x)
  {
    s+=(char('0'+(x%10)));
    x/=10;
  }
  reverse(s.begin(),s.end());
  int fl=1;
  for(int i=0;i<s.size();++i)
  {
    if(s[i]!=s[s.size()-i-1])fl=0;
  }
return fl;
}

LL p,q;
int main ()
{
  ios::sync_with_stdio(0);cin.tie(0);
atkin();
cin>>p>>q;
for(int i=0;i<primev.size();++i)
{
  dp1[primev[i]]++;
}

for(int i=1;i<=1000000;++i)dp1[i]+=dp1[i-1];

 for(int i=1;i<=1000000;++i)
 {
  if(pp(i)){dp2[i]++;}
  dp2[i]+=dp2[i-1];
 }
 LL maxi=0;

 for(LL i=1000000;i>=1;--i)
 {
  if(q*dp1[i]<=p*dp2[i])
  {
    maxi=max(maxi,i);
  }
 }
 if(maxi)
 cout<<maxi<<"\n";
else
{
  cout<<"Palindromic tree is better than splay tree";
}

 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 <limits.h>
#include <cstdint>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <cstring>
#include <deque>
#include <stack>
#include <queue>
#include <utility>
#include <iomanip>      // std::setprecision
using namespace std;
typedef long long l1;
typedef long long unsigned int lu1;
typedef long double ld;
#define FIO std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PI acos(-1.0)
#define pb push_back
// #define SORT(A) sort(A.begin(), A.end());
// #define REVERSE(A) reverse(A.begin(), A.end());
#define deb(x) cout << #x << ": " << x << "\n"
#define PrintArray(arr) for(auto w:arr)cout<<w<<" ";cout<<"\n";
#define pii pair<int,int>
#define pll pair<long long int , long long int>
#define puu pair<long long unsigned , long long unsigned>
#define int long long
const int MOD = 1e9+7;

vector<bool> prime(1e6+5,true);
void SieveOfEratosthenes(l1 n)
{
    prime[0]=false;
    prime[1]=false;
    for (lu1 p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (lu1 i=p*p; i<=n; i+= p)
                prime[i] = false;
        }
    }
}

int findLen(int n)
{
    int len = 0;
    while(n>0)
    {
        n/=10;
        len++;
    }
    return len;
}

int f(int n)
{
    int cnt = 0;
    for(int i=2;i<=n;i++) cnt+=(prime[i]);
    return cnt;
}

bool isPallindrome(int n)
{
    string str;
    while(n>0)
    {
        str+=to_string(n%10);
        n/=10;
    }
    string ss = str;
    reverse(ss.begin(),ss.end());
    return str==ss;
}

int g(int n)
{
    int len = findLen(n);
    int len1 = len-1, temp = 0;
    if(len1>0)
    {
        for(int i=1;i<=len1;i++)
        {
            temp+=9*pow(10,(i-1)/2);
        }
    }
    int cnt = temp;
    for(int i=pow(10,len-1);i<=n;i++) cnt+=(isPallindrome(i));
    return cnt;
}

int32_t main()
{
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    // #endif
    FIO;
    int t;
    t = 1;
    // cin>>t;
    for(int tc=0;tc<t;tc++)
    {
        SieveOfEratosthenes(1e6);
        int p, q;
        cin>>p>>q;
        int ans = -1;
        for(int n=1;n<=1e3;n++)
        {
            if(q*(f(n))<=p*(g(n)))
            {
                ans = n;
            }
        }
        if(ans==-1) cout<<"Palindromic tree is better than splay tree"<<"\n";
        else
        {
            cout<<ans<<"\n";
        }

    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define MAXVAL 1000000
bool prime[ MAXVAL + 1 ];
void criba(){
    memset( prime , 1 , sizeof( prime ) );
    prime[ 0 ] = 0;
    prime[ 1 ] = 0;
    for ( int i = 2 ; i * i <= MAXVAL ; i++ ){
        if ( prime[ i ] ){
            for ( int j = i*i ; j < MAXVAL ; j += i )
                prime[ j ] = 0;
        }
    }
}

int toi(string s){istringstream is(s);int x;is>>x;return x;}
string tos(long long t){stringstream st; st<<t;return st.str();}

vector< int > v ,r;

int p , q;
int pi( int n ){
    int pos = upper_bound( v.begin() , v.end() , n ) - v.begin();
    return pos;
}
int rub( int n ){
    int pos = upper_bound( r.begin() , r.end() , n ) - r.begin();
    return pos;
}

bool f( int x ){
    if( pi( x )*q > rub( x )*p ) return 1;
    return 0;
}
int main(){
    ios_base::sync_with_stdio( 0 );
    cin>>p>>q;
    criba();
    for ( int i = 1; i <= MAXVAL; i++ ){
        string s = tos( i );
        string s2;
        for ( int i = (int)s.size() - 1; i >= 0 ; i-- ) s2.push_back( s[ i ] );
        if( s2 == s ){
            int x = toi( s );
            r.push_back( x );
        }
    }
    for ( int i = 2 ; i <= MAXVAL; i++ )if( prime[ i ] )  v.push_back( i );
    int lo = 1 , hi = 100000 , mi;
    while( hi - lo > 1 ){
        mi = ( lo + hi )/2;
        if( f( mi ) ) hi = mi;
        else lo = mi;
    }
    cout<<(hi - 1)<<endl;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;

int bound=100000;

void extendedEuclidean(int arr[], vector<int> & primes){
    for(int i=2; i<bound; i++){
        if(!arr[i]){
            primes.push_back(i);
            arr[i]=i;
        }
        for(int j=0; j<primes.size() && primes[j]<=arr[i]; j++){
            if(primes[j]*i<bound){
                arr[i*primes[j]]=primes[j];
            }
            else{
                break;
            }
        }
    }
}

void solvePalindromeBinary(int binary[]){
    for(int i=0; i<bound; i++){
        int cur=i;
        vector<int> result;
        while(true){
            if(cur==0)break;
            result.push_back(cur%2);
            cur=cur/2;
        }

        bool ispalindrome=true;
        for(int j=0; j<result.size()/2; j++){
            if(result[j]!=result[result.size()-1-j]){
                ispalindrome=false;
                break;
            }
        }
        if(ispalindrome){
            binary[i]=1;
        }
    }
}

int main()
{
    int p, q;
    cin>>p>>q;
    int arr[bound];
    vector<int> primes;
    extendedEuclidean(arr, primes);
    int palindromeBinary[bound];
    int primeArray[bound];
    int primenumber[bound];
    int palnumber[bound];
    for(int i=0; i<bound; i++){
        primeArray[i]=0;
        palindromeBinary[i]=0;
        palnumber[i]=0;
        primenumber[i]=0;
    }
    for(int i=0; i<primes.size(); i++){
        primeArray[primes[i]]=1;            /*<-----------* PRIMEARRAY ARIS MTAVARI! */
    }

    solvePalindromeBinary(palindromeBinary);

    palnumber[0]=1;
    for(int i=1; i<bound; i++){
        if(primeArray[i]){
            primenumber[i]=primenumber[i-1]+1;
        }
        else{
            primenumber[i]=primenumber[i-1];
        }

        if(palindromeBinary[i]){
            palnumber[i]=palnumber[i-1]+1;
        }
        else{
            palnumber[i]=palnumber[i-1];
        }
    }

    int pasuxi=0;
    for(int i=1; i<bound; i++){
        if(q*primenumber[i]<=p*palnumber[i]){
            pasuxi=i;
        }
    }

    if(pasuxi==0){
        cout<<"Palindromic tree is better than splay tree";
    }
    else{
        cout<<pasuxi;
    }

    return 0;
}

#include <bits/stdc++.h>

typedef long long ll;

const int N = 10000100;

bool isPrime[N], isPalindromic[N];
int prefixPrimes[N], prefixPalindromes[N];

bool isPal(int n) {
    std::string str = std::to_string(n);
    for (int i = 0; i < str.size() / 2; ++i) {
        if (str[i] != str[str.size() - i - 1]) {
            return false;
        }
    }
    return true;
}

void build() {
    for (int i = 2; i < N; ++i) {
        isPrime[i] = true;
    }
    for (int i = 1; i < N; ++i) {
        isPalindromic[i] = isPal(i);
    }
    for (int i = 2; i < N; ++i) {
        if (isPrime[i]) {
            if (1ll * i * i < N) {
                for (int j = i * i; j < N; j += i) {
                    isPrime[j] = false;
                }
            }
        }
    }
    for (int i = 1; i < N; ++i) {
        prefixPrimes[i] = prefixPrimes[i - 1] + (int)isPrime[i];
        prefixPalindromes[i] = prefixPalindromes[i - 1] + (int)isPalindromic[i];
    }
}

int main(void) {
    build();
    int p, q;
    scanf("%d%d", &p, &q);
    int answer = 0;
    for (int n = 1; n < N; ++n) {
        if (q * prefixPrimes[n] <= p * prefixPalindromes[n]) {
            answer = n;
        }
    }
    printf("%d\n", answer);
    return 0;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<ii>    vii;
#define REP(a,b,i) for(ll (i) = (a); i < (b); i++)
#define MAX 1000000

bitset<MAX> palinq;

void palin(ll n){
  ll s = log10(n);
  if(n*10 > MAX)
    return;
  palinq[n] = true;
  //cout << n << endl;
  REP(1,10,i){
    palin(i + n*10 + pow(10.0,s+2)*i);
    palin(i + n*100 + pow(10.0,s+4)*i);
    if(n == 0)
      palin(i + pow(10.0,2)*i);
  }
}

int main(){
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  palin(0);
  REP(0,10,i)
    palin(i + 10*i);
  bitset<MAX> prime(false);
  vector<ll>  primeb(MAX,1);
  vector<ll>  palinb(MAX,0);
  for(int i = 3; i<MAX;i+=2){
    if(prime[i] == false){
      for(int j = i + i; j < MAX;j+=i){
        prime[j] = true;
      }
    }
  }
  REP(2,MAX,i){
    if(i%2 == 1)
      if(prime[i] == true)
        primeb[i] = primeb[i-1];
      else
        primeb[i] = primeb[i-1] + 1;
    else
      primeb[i] = primeb[i-1];
  }
  palinb[0] = 0;
  REP(1,MAX,i){
    if(palinq[i] == true)
      palinb[i] = palinb[i-1] + 1;
    else
      palinb[i] = palinb[i-1];
  }
  REP(0,1000,i){
    //cout << primeb[i] << " " << palinb[i] << " " << i << endl;
  }
  ll p,q;
  cin >> p >> q;
  /*ll lo = -1,hi=MAX;
  while(hi - lo > 0){
   ll mid = lo + (hi-lo)/2;
   bool p = primeb[mid] <= palinb[mid];
   cout << primeb[mid] <<" " << palinb[mid] << " " << mid << endl;
   if(p)
     lo = mid+1;
   else
     hi = mid;
  }*/
  int ma = 1;
  REP(1,MAX,i){
    if(primeb[i]*q <= palinb[i]*p)
      ma = i;
  }
  cout << ma << endl;
  return 0;
}

#include<cstdio>
#include<iostream>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
#include<cstring>
#define N 10000005
using namespace std;
int p,q;
int rub[N],pai[N];
bool v[N];
int t[10];
bool yes(int u)
{
	int i=0;
	memset(t,0,sizeof(t));
	while(u!=0)
	{
		i++;
		t[i]=u%10;
		u/=10;
	}
	for(int j=1;j<=i;j++)
	if(t[j]!=t[i-j+1])
	return false;
	return true;
}
int main()
{
	int j,k;
	scanf("%d%d",&p,&q);
	for(int i=2;i<=N-5;i++)
	{
		if(!v[i])
		{
			j=2*i;
			while(j<=N-5)
			{
				v[j]=1;
				j+=i;
			}

		}
	}
	pai[0]=-1;
	bool t=yes(10);
	for(int i=1;i<=N-5;i++)
	{
		if(yes(i))
		rub[i]=rub[i-1]+1;
		else rub[i]=rub[i-1];
		if(!v[i])
		pai[i]=pai[i-1]+1;
		else pai[i]=pai[i-1];
	}
	for(int i=N-5;i>=1;i--)
	if(rub[i]*p>=q*pai[i])
	{
		printf("%d",i);
		return 0;
	}
	return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<vector>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
int read()
{
	char ch=getchar();int x,f=1;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
	}
	x=ch-'0';
	while(1)
	{
		ch=getchar();
		if(ch<'0'||ch>'9') break;
		x=x*10+ch-'0';
	}
	return x*f;
}
const int maxn=10001000;
const int maxm=700100;
int vis[maxn],sum[maxm],check[maxn];
void sieve(int n)
{
	int m=(int)sqrt(n+0.5);
	memset(vis,0,sizeof(vis));
	for(int i=2;i<=m;i++) if(!vis[i])
		for(int j=i*i;j<=n;j+=i) vis[j]=1;
}
int genprime(int n)
{
	sieve(n);
	if(vis[n]==0) sum[n]=sum[n-1]+1;
	else sum[n]=sum[n-1];
	return sum[n];
}
void getpalind(int n)
{
	int flag=0,temp[20]={0},wei=0,org=n;
	while(n>=10) temp[++wei]=n%10,n/=10;
	temp[++wei]=n;
	for(int i=1;i<=wei;i++)
		if(temp[i]!=temp[wei-i+1]) {flag=1;break;}
		else if(i>=wei-i) break;
	if(flag==1) check[org]=check[org-1];
	else check[org]=check[org-1]+1;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int p=read(),q=read(),ans;
	for(int i=1;;i++)
	{
		int ret1,ret2;
		if(i==1) ret1=0;
		else ret1=genprime(i);
		if(i<10) check[i]=check[i-1]+1,ret2=check[i];
		else getpalind(i),ret2=check[i];
//		printf("debug :fi[i]:%d reb[i]:%d\n",ret1,ret2);
		if(ret1*q<=ret2*p) ans=i;
		if(i>200) break;
	}
	if(ans==0) printf("Palindromic tree is better than splay tree\n");
	else printf("%d\n",ans);
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define pb   push_back
#define mp   make_pair
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 1000000
#define INF 0x3f3f3f3f

int o[MAX] , p[MAX] , po;
void pre(){
	o[0] = o[1] = 1;
	REP(i , 2 , MAX){
		if(o[i] == 0) p[po ++] = i;// , cout << i << " ";
		REP(j , 0 , po){
			int tmp = p[j] * i;
			if(tmp >= MAX) break;
			o[tmp] = 1;
			if(i % p[j] == 0) break;
		}
	}
}
int ok[MAX] , B[MAX];
void TR(int now){
	int val = now;
	while(val) now = now * 10 + val % 10 , val /= 10;
	if(now < MAX) ok[now] = 1;
}
void TR2(int now){
	REP(i , 0 , 10){
		int to = now * 10 + i;
		int val = now;
		while(val) to = to * 10 + val % 10 , val /= 10;
		if(to < MAX) ok[to] = 1;
	}
}
void PRE(){
	REP(i , 0 , 10000){
		TR(i) , TR2(i);
	}
}
int A[MAX];
int n , m;
int32_t main(){
	pre();
	PRE();
	REP(i , 1 , MAX) A[i] = A[i - 1] + (1 - o[i]);
	REP(i , 1 , MAX) B[i] = B[i - 1] + ok[i];
	cin >> n >> m;
	int ans = -1;
	REP(i , 0 , MAX){
		if(A[i] * m <= B[i] * n) ans = max(ans , i);
	}
	if(ans == -1) cout << "Palindromic tree is better than splay tree" << endl;
	else cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

inline bool palindrome(int x) {
    static int a[9], dig;
    for (dig = 0; x; x /= 10, dig++)
        a[dig] = x % 10;
    for (int i = 0; (i << 1) < dig; i++)
        if (a[i] != a[dig - 1 - i])
            return false;
    return true;
}

bool prime[(int)1e7 + 5];

int main() {
    int cnt1 = 0, cnt2 = 0, res = 0, p, q;
    scanf("%d%d", &p, &q);
    for (int i = 2; i <= 1e7; i++) prime[i] = 1;
    for (int i = 2; i <= 5e6; i++)
        if (prime[i])
            for (int j = i << 1; j <= 1e7; j += i)
                prime[j] = false;
    for (int i = 1; i <= 1e7; i++) {
        cnt1 += palindrome(i);
        cnt2 += prime[i];
        if (q * cnt2 <= p * cnt1) res = i;
    }
    return printf("%d", res), 0;
}

#include<iostream>
#include<vector>
#include<stdlib.h>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#define ll long long
//#define int long long
using namespace std;

vector<char> w(5000001, true);
int cnt = 0, t;
int d[5000001];
int g[5000001];
bool ispolindrom(int n)
{
    int res = 0, k = n;
    while(n > 0)
    {
        res = res * 10 + n % 10;
        n /= 10;
    }
    if(k == res)
        return true;
    return false;
}
main()
{
    w[0] = w[1] = false;
    for(int i = 2; i * i <= 5000001; i++)
    {
        if(w[i])
        {
//         cnt++;
//         d[cnt] = i;
        for(int j = i * i; j <= 5000001; j += i)
        {
            w[j] = false;
        }
        }
    }
    int p, q, A;
    cin >> p >> q;
//    A = p / q;
//    for(int i = 1; i <= 5000001; i++)
//    {
//        if(ispolindrom(i))
//        g[++t] = i;
//    }
    int a = 0, b = 0, ans = -1;
    for(int i = 1; i <= 5000001; i++)
    {
        if(w[i])
            a++;
        if(ispolindrom(i))
            b++;
        if(a * q <= p * b)
        {
            ans = i;
        }
    }
    if(ans)
        cout << ans;
    else
        cout << "Palindromic tree is better than splay tree";
}

#include <bits/stdc++.h>
#define ll long long int
#define REP(i,n) for(i=0;i<n;i++)
#define RREP(i,a,b) for(i=a;i<b;i++)
#define pii pair<int,int>
#define pb(x) push_back(x)
#define FILL(a,x) memset(a,x,sizeof(a))
using namespace std;
int check_pali(int n)
{
	int b[6],k=0,i=0;
	while(n>0)
		b[i]=n%10,n/=10,k++,i++;
	i=0,k--;
	while(i<k)
	{
		if(b[i]!=b[k])
			return 0;
	i++,k--;}
	return 1;
}
int a[1000005],b[1000005];
int main()
{
	ll i,n,t,p,q,val,j,ans=0;
	REP(i,1000005)
	a[i]=1;
	cin >>p>>q;
	for(i=2;i<=1000000;i++)
	{
		if(a[i]==0)
			continue;
		for(j=i*i;j<=1000000;j+=i)
		{
			a[j]=0;
		}
	}
	a[0]=0,a[1]=0;
	for(i=2;i<=1000000;i++)
		a[i]+=a[i-1];
	b[0]=0;
	for(i=1;i<=950000;i++)
	{
			b[i]=b[i-1]+check_pali(i);
	}
	for(i=1;i<=950000;i++)
	{
			if(q*a[i]<=p*b[i])
			ans=i;
	}
	//cout << a[900000]<<" "<<b[900000]<<endl;
	if(ans)
	cout << ans;
else cout << "Palindromic tree is better than splay tree";
	return 0;
}

/*

  author: Slience_K
  Belong: C++
  Pro: Codefoeces 569 - C

*/
#include <cstdio>
#include <cstring>
#define maxn 300000
using namespace std;
int p , q , sum[ maxn + 5 ] , rub , ans;
bool z[ maxn + 5 ];
void Prime(){
	memset( z , true , sizeof( z ) );
	for( int i = 2 ; i <= maxn ; i++ )
		if ( z[ i ] )
			for( int j = 2 * i ; j <= maxn ; j += i )
				z[ j ] = false;
	for( int i = 2 ; i <= maxn ; i++ )
		if ( z[ i ] ) sum[ i ] = sum[ i - 1 ] + 1;
		else sum[ i ] = sum[ i - 1 ];
}
bool Rub( int x ){
	int k , z = 0;
	k = x;
	while( k ){
		z = z * 10 + k % 10;
		k /= 10;
	}
	return x == z;
}
int main(){
//	freopen( "Primes or Palindromes.in" , "r" , stdin );
	scanf( "%d%d" , &p , &q );
	Prime();
	ans = 0;
	for( int i = 1 ; i <= maxn ; i++ ){
		if ( Rub( i ) ) rub++;
		if ( q * sum[ i ] <= p * rub )
			ans = i;
	}
	ans ? printf( "%d\n" , ans ) : printf( "Palindromic tree is better than splay tree\n" );
	return 0;
}

#include<stdio.h>
#include<algorithm>
#include<math.h>
int prr(int x)
{
    int i=0,flag=0;
    if(x==1)
    return 0;
    for(i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        {
           flag=1;
           break;
        }
    }
    if(flag==0)
    {
        //printf("%d\n",x);
       return 1;
    }
    else
    return 0;
}
int ruba(int x)
{
    int z=0,t=0,rem=0;
    t=x;
    while(t)
    {
      rem=t%10;
      z=z*10+rem;
      t=t/10;
    }
    if(z==x)
    {
        //printf("A %d\n",x);
       return 1;
    }
    else
    return 0;
}
int main()
{
    int p,q,count,j,flag=0,chic=0;
    scanf("%d %d",&p,&q);
    int i=1;
    int primes=0;
    int rub=1;

      while(1)
      {

         i++;
         if(prr(i)==1)
         primes++;
         if(ruba(i)==1)
         rub++;
         //printf("%d %d\n",primes,rub);
         if(q*primes>p*rub && flag==0)
         {
            flag=1;
            j=i-1;
            //printf("%d\n",j);
         }
         else if(q*primes<=p*rub)
         flag=0;
         if(q*primes>p*rub+p)
         break;

      }

    printf("%d",j);
    return 0;
}

    #include<bits/stdc++.h>
    #define MAXN 1000001
    using namespace std;

    int sum[MAXN];
    int palin[MAXN];
    bool sieve[MAXN];

    bool isPalin(int x)
    {
        char s[10];
        sprintf(s,"%d",x);
        int len=strlen(s);
        for(int i=0;i<len;i++){
            if(s[i]!=s[len-i-1])return false;
        }
        return true;
    }
    int numPalin(int x)
    {
        int res=0;
        palin[x]=palin[x-1];
        if(isPalin(x))palin[x]++;
        return palin[x];
    }
    int p, q;
    int main()
    {

        cin >> p >> q;
        memset(sieve, 1, sizeof sieve);
        sieve[0] = 0;
        sieve[1] = 0;
        int root = sqrt(MAXN);
        for(int i = 2; i < root; i++){
            if(sieve[i]){
                for(int x = i*2; x < MAXN; x+=i){
                    sieve[x] = 0;
                }
            }
        }
        for(int i = 0; i < MAXN; i++){
            sum[i] += sum[i-1] + sieve[i];
        }
        int lo=1;
        for(int i=1;i<=1000000;i++)
        {
            if(sum[i]<=(numPalin(i)*p/q))
                lo=i;
        }
        //cout<<sum[108]<<endl;;
        cout << lo << endl;
    }

#include <iostream>
#include <string.h>
#include <string>
#include<sstream>
#include <cstdio>
#include <cmath>
#define maxx 2000000
using namespace std;
int x[maxx];

bool hw(int x)
{
	char s[10];
	sprintf(s,"%d",x);
	int p=0,q=strlen(s)-1;
	while(p<q) if (s[p]!=s[q]) return 0;else ++p,--q;
	return 1;
}

bool s(int k)
{
    if(x[k] == 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    double p,q,A;
    cin>>p>>q;
    A = p/q;
    memset(x,0,sizeof(int)*maxx);
    for(int i = 2;i<maxx;i++)
    {
        if(x[i] == 0)
        {
            x[i] = 1;
            //cout<<i<<" ok "<<endl;
        }

        for(int k = i+i;k<maxx;k+=i)
        {
            x[k] = 2;
        }
    }
    //cout<<x[7]<<endl;
//    cout<<manys(171)<<" "<<manyhw(171)<<endl;

    int ans = 0;
    double ss = 0,hh = 0;
    for(int i = 1;i<maxx;i++)
    {
        if(s(i))
        {
            ss++;
        }
        if(hw(i))
        {
            hh++;
        }
        if(fabs(ss - A*hh)<=0.0000001)
        {
            ans = i;
            //cout<<"i = "<<i<<" ss = hh = "<<ss<<" "<<hh<<endl;
        }

    }
    if(ans>0)
        cout<<ans;
    else
    {
        cout<<"Palindromic tree is better than splay tree";
    }
    return 0;
}

#include <cstdio>

const int N = 200001;
bool sieve[N];
int sieve_sum[N], palind_sum[N];

inline bool is_palindrome(int n) {
  int reversed = 0;
  for (int i = n; i > 0; i /= 10) {
    reversed = reversed * 10 + i % 10;
  }
  return reversed == n;
}

inline void build_sieve() {
  for (int i = 2; i <= N; ++i) {
    sieve[i] = true;
  }
  for (int i = 2; i * i <= N; ++i) {
    if (sieve[i]) {
      for (int j = i * i; j <= N; j += i) {
        sieve[j] = false;
      }
    }
  }
  for (int i = 2; i <= N; ++i) {
    sieve_sum[i] += sieve_sum[i - 1];
    if (sieve[i]) {
      ++sieve_sum[i];
    }
  }
}

inline void build_palind() {
  for (int i = 1; i <= N; ++i) {
    palind_sum[i] += palind_sum[i - 1];
    if (is_palindrome(i)) {
      ++palind_sum[i];
    }
  }
}

int main() {
  int p, q;
  scanf("%d%d", &p, &q);
  build_sieve();
  build_palind();
  int ans = 0;
  for (int i = 0; i <= N; ++i) {
    if (sieve_sum[i] * q <= palind_sum[i] * p) {
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int pr[1000005];
void seive()
{
	int i,j;
	pr[0] = 1;
	pr[1] = 1;
	for(i=2;i*i<=1000005;i++)
		if(!pr[i])
			for(j=2*i;j<=1000005;j+=i)
				pr[j] = 1;
}
int palin(int num)
{
	string s = to_string(num);
	string tmp = s;
	reverse(tmp.begin(),tmp.end());
	if(s == tmp)
		return 1;
	return 0;
}
int main()
{
	long double p,q,A;
	cin>>p>>q;
	A = p/q;
	seive();
	int i,ans = 0;
	long double cnt_pr = 0, cnt_pal = 0;
	for(i=1;i<=1000005;i++)
	{
		if(!pr[i])
			cnt_pr++;
		if(palin(i))
			cnt_pal++;
		if(A*cnt_pal >= cnt_pr)
			ans = i;
	}
	if(!ans)
	    cout<<"Palindromic tree is better than splay tree"<<endl;
	else
	    cout<<ans<<endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 5000005

int prime[mxn],palindrome[mxn];
int p,q;

int checkpalin(int n){
int x=n,z=0;
while(n){
    z=z*10+n%10;
    n/=10;
}
return (z==x);
}

void pre(){
prime[2]=1;
for(int i=3; i<mxn; i+=2)prime[i]=1;
for(int i=3; i*i<mxn; i+=2)
    if(prime[i])for(int j=i*i; j<mxn; j+=i+i)prime[j]=0;
for(int i=3; i<mxn; ++i)prime[i]+=prime[i-1];
for(int i=1; i<mxn; ++i)
    palindrome[i]=palindrome[i-1]+checkpalin(i);
}

bool check(int n){
return (q*prime[n]<=p*palindrome[n]);
}

int main(){
sp;
pre();
cin>>p>>q;
for(int i=mxn-1; i>0; --i)
    if(check(i)){
        cout<<i;
        return 0;
    }
cout<<"Palindromic tree is better than splay tree";
return 0;}

	#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	// #include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
// #define f(i,a,b) for(ll i=a;i<b;i++)
// #define rep(i,n) f(i,0,n)
	#define s second
# define M_PI           3.14159265358979323846  /* pi */
using namespace std;
const ll N = 10000000;
ll lp[10000001];
vector<ll> pr;
vll rub;
bool isPalin(ll n){
	string st = to_string(n);
	ll si = st.size();
	for(ll i = 0 ; i < si/2 ; i++){
		if(st[i] != st[si-1-i])
			return false;
	}
	return true;
}
int main(){
	std::ios::sync_with_stdio(false);
	rub.push_back(1);
	for (ll i=2; i<=N; ++i) {
		if(isPalin(i))
			rub.push_back(i);
    if (lp[i] == 0) {
        lp[i] = i;
        pr.push_back (i);
    }
    for (ll j=0; j<(ll)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
        lp[i * pr[j]] = pr[j];
	}
	// cout << pr.size() << endl;
	ll p,q;
	cin >> p >> q;
	ll l  = 1, r = 10000000;
	while(l+1 < r){
		ll m = (l+r)/2;
		auto i1 = upper_bound(pr.begin(), pr.end(), m);
		ll a = i1 - pr.begin();
		auto i2 = upper_bound(rub.begin(), rub.end(), m);
		ll b = i2 - rub.begin();
		if(q*a <= p*b)
			l = m;
		else
			r = m;
	}
	cout << l << endl;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e7+10000;
int x[N],y[N];
bool b[N];
int k[10];
bool ff(int x)
{
    int top=0;
    while(x)
    {
        k[top++] = x%10;
        x/=10;
    }
    int l = top/2;
    for(int i=0;i<l;i++)
        if(k[i] != k[top-1]) return 0;
    return 1;
}
int main()
{
    x[1] = 0;
    for(int i=2;i<N;i++)
    {
        x[i] = x[i-1];
        if(!b[i])
        {
            x[i]++;
            int j = i+i;
            while(j<N)
            {
                b[j] = 1;
                j+=i;
            }
        }
    }
    y[0] = 0;
    for(int i=1;i<N;i++)
    {
        y[i] = y[i-1] + ff(i);
    }
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        int i;
        int ans = 0;
        for(i=N-1;i>0;i--)
        {
            if(x[i] * m <=y[i] * n) break;
        }
        if(i == 0)
            printf("Palindromic tree is better than splay tree\n");
        else
            printf("%d\n",i);
    }
    return 0;
}

/*
 *    11582 - Colossal Fibonacci Numbers
 */
#include<fstream>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<list>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<utility>
#include<queue>
#include<deque>
#include<ctime>
#include<complex>
#include<bitset>
#include<time.h>

using namespace std;
#define PB push_back
#define LL long long
#define MP make_pair
typedef unsigned long long ULL;
typedef pair<int, int> ii;
typedef vector<ii> vii;

#define DBG 0

#define fori(i,a,b) for(int i = (a); i < (b); i++)
#define forie(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i > (b); i--)
#define forde(i,a,b) for(int i = (a); i >= (b); i--)
#define forls(i,a,b,n) for(int i = (a); i != (b); i = n[i])
#define mset(a,v) memset(a, v, sizeof(a))
#define mcpy(a,b) memcpy(a, b, sizeof(a))

#define dout  DBG && cerr << __LINE__ << " >>| "
#define checkv(x) dout << #x"=" << (x) << " | "<<endl
#define checka(array,a,b) if(DBG) { \
dout << #array"[] | " << endl; \
forie(i, a, b) cerr << "[" << i << "]=" << array[i] << " |" << ((i - (a)+1) % 5 ? " " : "\n"); \
if (((b)-(a)+1) % 5) cerr << endl; \
}

#define redata(T, x) T x; cin >> x
#define MIN_LD -2147483648
#define MAX_LD  2147483647
#define MIN_LLD -9223372036854775808
#define MAX_LLD  9223372036854775807
#define MAX_INF 18446744073709551615
const int INF = 0x7fffffff;//use double for addition
inline int  reint() { int d; scanf("%d", &d); return d; }
inline long relong() { long l; scanf("%ld", &l); return l; }
inline char rechar() { scanf(" "); return getchar(); }
inline double redouble() { double d; scanf("%lf", &d); return d; }
inline string restring() { string s; cin >> s; return s; }

typedef set<int> Set;
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
//set_union(ALL(x1),ALL(x2),INS(x)),set_intersection

const int maxn = 1000000+10;

bool is[maxn]; int prm[maxn];
int getprm(int n){
    if (n<=1) return 0;
    n++;
    int i, j, k = 0;
    int s, e = (int)(sqrt(0.0 + n) + 1);
    memset(is, 1, sizeof(is));
    prm[k++] = 2; is[0] = is[1] = 0;
    for (i = 4; i < n; i += 2) is[i] = 0;
    for (i = 3; i < e; i += 2) if (is[i]) {
        prm[k++] = i;
        for (s = i*2, j= i*i;j<n;j+=s) is[j] = 0;
    }
    for ( ; i < n; i += 2) if (is[i]) prm[k++] = i;
    return k; //number of primes
}

int len(int a){
    int ans = 0;
    while(a>0){
        a/=10;
        ans++;
    }
    return ans;
}
int pal[1000];
int getpaldigit(int d){
    int& ans = pal[d];
    if (ans > 0) return ans;
    if (d == 1) {ans = 9;return ans;}
    else if (d == 2) {ans = 9; return ans;}
    else if(d%2 == 1) ans = 10*getpaldigit(d-1);
    else ans = 10*getpaldigit(d-2);
    return ans;
}
bool ispal(int a){
    int b = a;
    int rev = 0;
    while(a>0){
        int dig = a%10;
        rev = rev*10 + dig;
        a /= 10;
    }
    return b==rev;
}
int rev(int a){
    int r = 0;
    while(a>0){
        int dig = a%10;
        r = r*10 + dig;
        a /= 10;
    }
    return r;
}
int getpal(int n){
    int l = len(n);
    //first calculate the number of pals with digits less than l
    int ans = 0;
    memset(pal,0,sizeof(pal));
    fori(i,1,l){
        ans += getpaldigit(i);
    }//cout << l << endl;
    //then calculate the number of pals with the same digits as n
    int l1 = l/2;
    int h1 = n/pow(10,l1);
    ans += h1-pow(10,len(h1)-1);
    //if (ispal(n)) ans++;
    int h2 = n-h1*pow(10,l1);
    if(len(h1)==len(h2)){
        if(rev(h1)<=h2) ans++;
    }
    else{
        h1 = h1/10;
        if(rev(h1)<=h2) ans++;
    }
    return ans;

}
int p,q;
int main(void){
    cin >> p >> q;
    int i = 1;
    int maxi = 0;
    while(i<=10000){
        if(getpal(i)*p>=getprm(i)*q) {maxi = i;}
        i++;
    }
    //cout << getpal(172)*p << ' ' << getprm(172)*q<<endl;
    if (maxi) cout << maxi << endl;
    else cout << "Palindromic tree is better than splay tree" << endl;
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;

int pi[10000000+10] , rub[10000000+10];
bool mrk[10000000+10];
int p,q;

void prime(){
    mrk[1]=true;
    for(int i=2; i<10000000+10 ; i++){
        if(!mrk[i]){
            for(int j=2*i ; j<10000000+10 ; j+=i)
                mrk[j]=true;
        }
    }
}

bool pal(int x){
    if(x<10) return true;
    int t=x , s=0;
    while(x>0){
        s*=10;
        s+= x%10;
        x/=10;
    }
    if(s==t) {
        return true;
    }
    return false;
}

int main(){
    prime();
    cin>>p>>q;
    int ans=-1;
    rub[1]=1;
    if(pi[1]*q<=rub[1]*p) ans=1;
    for(int i=2 ; i<10000000+10; i++){
        pi[i]=pi[i-1];
        if(!mrk[i]) pi[i]++;
        rub[i]=rub[i-1];
        if(pal(i)) rub[i]++;
        if(pi[i]*q<=rub[i]*p) ans=i;
    }

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

    return 0;
}

#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define inf 1<<30
#define lc(x) x<<1
#define rc(x) x<<1|1
#define m(a,b) (a+b)/2
#define EPS 1e-6
#define PI 3.1415926535897932384
#define For(a,b,c) for(int a = b;a<=c;a++)
#define pb push_back
#define mp make_pair
#define io cin.sync_with_stdio(0); cin.tie(0);

using namespace std;
const int MAX =  100005;

double p,q;
bool sieve[MAX];
int numprimes[MAX];
int numpal[MAX];
bool done = false;
int main() {
      memset(sieve,1,sizeof sieve);
      sieve[1] = 0;
      sieve[0] = 0;
      for (int i = 2;i<=316;i++) {
            if (sieve[i]) {
                  for (int j = i+i;j<=316;j+=i)
                        sieve[j] = 0;
            }
      }
      For(i,1,MAX) numprimes[i] = numprimes[i-1] + sieve[i];

      For(i,1,MAX) {
            int NEW = 0, temp = i;
            while (temp != 0) {
                  NEW = NEW * 10 + temp % 10;
                  temp /= 10;
            }
            numpal[i] = numpal[i-1] + (NEW == i);
      }
      cin >> p >> q;

      int low = 1, high = MAX;
      while (low < high) {
            int mid = m(low,high);
            double NUMPAL = numpal[mid];
            double NUMPRI = numprimes[mid];
           // cout << mid << " " << NUMPRI << " " << NUMPAL*p/q << "(" << NUMPAL << ")" <<  endl;
            if (NUMPRI <= NUMPAL*p/q) {
                  if (numprimes[mid+1] > (double)p/(double)q*numpal[mid+1]) {cout << mid << endl;done = 1;break;}
                  else {
                        low = mid + 1;
                 //       cout << " UP " << endl;
                  }
            } else {
                  high = mid;
             //     cout << " DOWN " << endl;
            }
          //  cout << low << endl;
            if (!done) cout << low << endl;

      }
     // cout << numprimes[172] << " " << numpal[172] << endl;
}

#include <bits/stdc++.h>

using namespace std;
bool prime[1000005];
int contPrime[1000005];
int contPalindrome[1000005];
void er()
{
    for(long long i = 2;i*i <= 1000000;i++)
    {
        if(!prime[i])
        {
            for(long long j = i*2;j <= 1000000;j += i)
                prime[j] = true;
        }
    }
}
bool pal(string& s)
{
    for(int i = 0;i < s.length() / 2;i++)
    {
        if(s[i] != s[s.length() - i - 1])
            return false;
    }
    return true;
}
int main()
{
    double p,q;
    cin >> p >> q;
    double A = (p/q);
    er();
    int f = 0;
    for(int i = 2;i <= 1000000;i++)
    {
        if(!prime[i])
            f++;

        contPrime[i] = f;
    }
    f = 0;
    for(int i = 1;i <= 1000000;i++)
    {
        stringstream ss;
        ss << i;
        string t = ss.str();
        if(pal(t))
            f++;

        contPalindrome[i] = f;
    }
    /*int lo = 1;
    int hi = 1000000;
    while(lo != hi)
    {
        int mid = (lo + hi) / 2;
        long long pr = contPrime[mid];
        long long palin = contPalindrome[mid];
        if(pr <= A * palin)
            lo = mid + 1;
        else
            hi = mid;
    }*/
    int Best = 0;
    for(int i = 1;i <= 1000000;i++)
    {
        if(contPrime[i] <= A * contPalindrome[i])
            Best = i;
    }
    if(Best != 0)
        cout << Best;
    else
        cout << "Palindromic tree is better than splay tree";
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define frs first
#define snd second

const int INF = (1e9+7);

bool check(int x) {
    string s = "";
    while (x > 0) {
        s +=(char) ('0' + (x % 10));
        x /= 10;
    }
    int n = (int)s.length();
    for (int i = 0; i < n / 2; ++i) {
        if (s[i] != s[n - 1 - i]) return false;
    }
    return true;
}

bool is_prime(int x) {
    for (int i = 2; i * i <= x; ++i)
        if (x % i == 0) return false;

    return true;
}

int  main(){

//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

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

    int prime = 0, polindr = 0;
    int m = -1;
    bool f = false;

    for (int i = 1; i < 10000; ++i) {
        if (is_prime(i) && i != 1) prime++;
        if (check(i)) polindr++;
        if (prime * q <= p * polindr) {
            m = i;
        } else {
            f = true;
        }
    }

    if ((!f && m != 1) || m == -1) {
        printf("Palindromic tree is better than splay tree");
    } else {
        printf("%d", m);
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
#include <chrono>
using namespace std::chrono;
// Use auto keyword to avoid typing long
// type definitions to get the timepoint
// at this instant use function now()

//const int mod=1e9+7;
const ll inf=1LL<<32;
vector<ll> seive(20000000,1),rub(10000000,0);
void buildseive(){
    seive[0]=0;
    seive[1]=0;
    for(int i=2;i*i<=10000000;i++){
        if(seive[i])
        for(int j=i*i;j<10000000;j+=i)
        seive[j]=0;
    }
    fr(i,1,seive.size())
    seive[i]+=seive[i-1];
}
int rev(int x){
    int ans=0;
    while(x>0){
        ans=ans*10+x%10;
        x/=10;
    }
    return ans;
}
int nod(int x){
    int c=0;
    while(x>0){
        c++;
        x/=10;
    }
    return c;
}
void buildrub(){
    int y;
    fr(x,1,5001){
        y=rev(x);
        y=x*pow(10,nod(y))+y;
        if(y<10000000)
        rub[y]=1;
        y=rev(x/10);
        y=x*pow(10,nod(y))+y;
        if(y<10000000)
        rub[y]=1;
    }
    fr(i,1,10000000)
    rub[i]+=rub[i-1];
}
void solve(){
    buildseive();
    buildrub();
    ll p,q;
    cin>>p>>q;
    fb(i,10000000-1,0){
        if(q*seive[i]<=p*rub[i]){
            cout<<i;
            return;
        }

    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //cout<<better(3,2)<<endl;
    auto start = high_resolution_clock::now();

    int t;
    t=1;
    while(t--)
    solve();
    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
//    cout << "duration="<<duration.count() << endl;
}

#include <bits/stdc++.h>
using namespace std;
const int MAX=15000000;
int palind[MAX], prime[MAX];
void sieve(){

for(int i=2;i*i<MAX;i++){
        if(prime[i])continue;
        for(int j=i*i;j<MAX;j+=i){
            prime[j]=1;
        }
}
for(int i=2;i<MAX;i++){
        if(prime[i])prime[i]=0;

        else prime[i]=1;
        prime[i]+=prime[i-1];}
}
bool is_palind(int x){
    int count=0,arr[10];
    while(x){
    arr[count++]=x%10;
    x/=10;
    }
    for(int i=0 ; i<count/2; i++ )if(arr[i]!=arr[count-i-1])return false;

    return true;
}
int main()
{
    prime[0]=0;prime[1]=0;
    sieve();
    for(int i=1;i<MAX;i++){
    if(is_palind(i))palind[i]=1;
    palind[i]+=palind[i-1];
    }

    int n=0,p,q;
    cin>>p>>q;
    for(int i=0;i<MAX;i++){
        if(p*palind[i]>=q*prime[i])
            n=i;
    }

    cout<<n<<endl;

return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int nax = 1100000;
vector<ll>primes;
void sieve ()
{
    const int N = nax;
    vector<bool>ck (N + 1, 0);
    primes.push_back(2);
    for(ll i = 4; i <= N; i += 2) ck[i] = 1;
    for(ll i = 3; i * i <= N; i += 2) if(!ck[i]) {
        for(ll j = i * i; j <= N; j += i + i) ck[j] = 1;
    }
    for(ll i = 3; i <= N; i += 2)
        if(!ck[i])primes.push_back(i);
}
template<typename T>
string dtos(T x, string s = "") {
    while (x) {
        T r = x % 10;   s += char(r - '0');
        x /= 10;
    } reverse (s.begin(), s.end());
    return s;
}
void solve()
{
    sieve();
    reverse(primes.begin(),primes.end());
    int p,q; cin >> p >> q;
    auto palin = [] (string s) {
        for(int i=0,j=s.size()-1;i<j;i++,j--) {
            if(s[i]!=s[j])return 0;
        }
        return 1;
    };
    int prms = 0;
    int palns = 0;
    int best = 1;
    for(int i=1; i<=nax; i++) {
        if(palin(dtos(i)))palns++;
        if(primes.back()==i)prms++,primes.pop_back();
        int x = prms*q; int y = palns*p;
        if(x<=y)best = i;
    }
    cout << best << "\n";
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll N=100001;
const ll K=1e7;

ll fact[K+1];
ll pal[K+1];
vector<ll> pri;

bool pali(ll n){
	ll s=0;
	ll aux=n;
	while(aux>0){
		s=s*10+aux%10;
		aux=aux/10;
	}
	return s==n;
}

void extSieve(){
	for( ll i=2; i*i <= K; ++i ){
		if( fact[ i ] == 0 ){
			for( ll j = i*i ; j <= K ; j+=i ) if( fact[j ] == 0) fact[ j ] = i;
		}
	}
	for( ll i=2; i<=K; ++i ){
		if( fact[ i ] == 0 ){
			fact[ i ] = i;
			pri.push_back(i);
		}
		pal[i]=pal[i-1]+pali(i);
	}
	return;
}

ll bb(ll l, ll r, ll p, ll q){
	while(l!=r){
		ll med=(l+r)/2;
		ll aux=(upper_bound(pri.begin(),pri.end(),med)-pri.begin());
		if(q*aux-p*pal[med]<=0){
			l=med+1;
		}else{
			r=med;
		}
	}
	ll aux=upper_bound(pri.begin(),pri.end(),l)-pri.begin();
	while(aux*q-p*pal[l]>0){
		l--;
		if(l==0){
			break;
		}
		aux=upper_bound(pri.begin(),pri.end(),l)-pri.begin();
	}
	return l;
}

int main(){
	pal[1]=1;
	extSieve();
	ll p,q;
	cin>>p>>q;
	ll rep=bb(10,1e7,p,q);
	if(rep==0){
		cout<<"Palindromic tree is better than splay tree"<<endl;
	}else{
		cout<<rep<<endl;
	}
	return 0;
}