require 'Prime'

def solve(n, c)
  return (n == 1 ? 11 : "99"*n) if c < 0

  1.step(10**n, 2).map{|i|
    s = (("%0#{n}d"%i).reverse + c.to_s + "%0#{n}d"%i).to_i
    s.prime? ? s : 0
  }.max
end

puts solve(*gets.split.map(&:to_i))