package main import ( "fmt" "sort" ) func main() { var K, N int fmt.Scan(&K, &N) pl := Sieve(N) sort.Ints(pl) i := 0 for pl[i] < K { i++ } pl = pl[i:] hashList := make([]int, len(pl)) for i, m := range pl { hashList[i] = hash(m) } ans := 0 ans_len := 0 for i := 0; i < len(hashList); i++ { for j := i + 1; j < len(hashList); j++ { flag := true for _, v := range hashList[i:j] { if v == hashList[j] { flag = false } } if flag { if j-i+1 > ans_len { ans = pl[i] ans_len = j - i + 1 } else if j-i+1 == ans_len { ans = max(ans, pl[i]) } } else { break } } } fmt.Println(ans) } func hash(m int) int { for m >= 10 { n := m m = 0 for n > 0 { m += n % 10 n /= 10 } } return m } func Sieve(n int) []int { isNotPrime := make([]bool, n+1) primeList := make([]int, 0) isNotPrime[0] = true isNotPrime[1] = true for i := 2; i <= n; i++ { if !isNotPrime[i] { // 素数の場合 primeList = append(primeList, i) for j := 2 * i; j <= n; j += i { isNotPrime[j] = true } } } return primeList } func max(a, b int) int { if a > b { return a } return b }