Var
x,i,n,j,s:integer;
finish:boolean;
f:Text
begin
Assign(f,'funny-numbrs.in');
Reset(f);
Read(f,x);
Close(f);
i:=x+1; finish:=false;
while (i<=10000) and (not finish) do begin<br> s:=0; n:=i;
for j:=1 to 5 do
begin s:=s+sqr((n mod 10)); n:=(n div 10) end;
if (s mod 7)=0 then finish:=true
else Inc(i)
end;
Assign(f,'funny-numbrs.out');
Rewrite(f);
if finish then Writeln(f,i) else Writeln(f,0);
Close(f)
end.