### constant

MAX_P = 100000

### subroutines

def gen_primes(max_p)
  primes = Array.new(max_p + 1){true}
  primes[0] = primes[1] = false

  pnums = []

  s_max_p = Math.sqrt(max_p + 0.5).to_i

  for p in (2..s_max_p)
    if primes[p]
      pnums << p
      for q in (p * p).step(max_p, p)
        primes[q] = false
      end
    end
  end

  for p in ((s_max_p + 1)..MAX_P)
    if primes[p]
      pnums << p
    end
  end

  return pnums
end

def pal_rec(k)
  if k >= $n
    pln = $c * (10 ** $n)
    for i in (0...$n)
      pln += $pals[i] * (10 ** (2 * $n - i) + 10 ** i)
    end

    for pi in $pnums
      break if pi * pi > pln
      return 0 if pln % pi == 0
    end

    return pln
  end

  9.downto(0) do |pl|
    $pals[k] = pl
    mpl = pal_rec(k + 1)
    return mpl if mpl > 0
  end

  0
end

### main

$pnums = gen_primes(MAX_P)
#p $pnums.length

$n, $c = gets.strip.split(' ').map{|s| s.to_i}

if $c < 0
  puts ($n == 1 ? 11 : 10 ** (2 * $n) - 1)
  exit 0
end

$pals = []

puts pal_rec(0)