open System let dprintfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt let primes n = let mid = float n |> sqrt |> floor |> int let table = Array.init (n+1) (fun _ -> true) seq { for i in 2 .. mid do if table.[i] then yield i for j in (i+i) .. i .. n do table.[j] <- false for i in (mid+1) .. n do if table.[i] then yield i } let sum_digit n = let rec f acc i = let m = i % 10 let d = i / 10 let acc' = acc+m if d = 0 then if acc' < 10 then acc' else f 0 acc' else f acc' d f 0 n [] let main argv = let K = Console.ReadLine() |> int let N = Console.ReadLine() |> int primes N |> Seq.filter (fun x -> x >= K) |> Seq.toArray |> fun ps -> let hash = Array.map sum_digit ps let rec loop ans maxcnt j = if j = hash.Length then ans else let rec f s i = if i = hash.Length || Set.exists ((=) hash.[i]) s then s.Count else f (Set.add hash.[i] s) (i+1) let cnt = f Set.empty j if cnt >= maxcnt then loop ps.[j] cnt (j+1) else loop ans maxcnt (j+1) loop 0 0 0 |> printfn "%d" 0