program fibo;
var f,g:text;
n:longint;
procedure kt_ndl;
begin
Assign(f,'FIBO.INP');
Assign(g,'FIBO.out'); rewrite(g);
{I-} reset(f); {I-} reset(f); {I+}
if IOresult<>0 then
begin
rewrite(f);
reset(f);
end;
readln(f,n);
close(f);
end;
function ktnt(k:longint);
var l:longint;
begin
ktnt:=false;
if k<2 then exit;
for l:=2 to trunc(sqrt(k)) do
if k mod l=0 then exit;
ktnt:=true;
end;
procedure xuly;
var f1,f2,fn,max:longint;
begin
f1:=1; f2:=1; max:=1;
while f2<n do
begin
fn:=f1+f2;
f1:=f2;
f2:=fn;
if (f2<n) and ktnt(f2) then max:=f2;
end;
write(g,max);
close(g);
end;
begin
kt_ndl; xuly;
end.
#Nguyenduyhungk6