from itertools import * from bisect import * from math import * from collections import * from heapq import * from random import * from decimal import * import numpy as np import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] dij = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): def xtobit(x): res=0 for c in str(x): res|=1<5000000:break if prime[x]: bit=xtobit(x) if bit|a!=a: if s==a: ans=max(ans,x-l-1) #print(l,x,x-l-1,ans) l=x+1 s=0 else: s|=bit #pp.append(x) for y in range(x**2,5000001,x*2): prime[y]=0 if s==a: ans=max(ans,5000000-l) print(ans) main()