Var c,i:integer; function sov(k:integer):boolean; var j,s:integer; begin result:=false; s:=0; for j:=1 to k div 2 do if k mod j=0 then s:=s+j; if s=k then result:=true; end; begin read(c); i:=1; while (sov(c+i)=false) and (sov (c-i)=false) do i:=i+1; if sov(c+i)=true then writeln(c+i) else writeln(c-i) end.
function sov(k:integer):boolean;
var j,s:integer;
begin
result:=false;
s:=0;
for j:=1 to k div 2 do if k mod j=0 then s:=s+j;
if s=k then result:=true;
end;
begin
read(c);
i:=1;
while (sov(c+i)=false) and (sov (c-i)=false) do i:=i+1;
if sov(c+i)=true then writeln(c+i) else writeln(c-i)
end.