def f(x,i): if i<300: d=10**i for z in range(10): y=d*z+x if y**2%(d*10)==1:f(y,i+1) elif`x`[0]in"369":print x f(input(),3)