uses crt;
var j,i,m,a,b,t:longint;
{----------------------}
Function kt(n:longint):boolean;
var i,d:integer;
begin
kt:=false;
d:=0;
For i:=1 to n do
if n mod i=0 then inc(d);
if d=2 then kt:=true;
end;
{----------------------}
begin
clrscr;
Write('Nhap m= ');
readln(m);
a:=0;
b:=1;
Repeat
a:=a+b;
b:=a+b;
Until (a>=m) and (b>=m);
if a<b then begin t:=a;a:=b;b:=t;end;
Repeat
a:=a-b;
b:=b-a;
Until ( (kt(a)) and (a<m)) or ( (kt(b)) and (b<m) );
If a>b then writeln(a);
if b>a then writeln(b);
{----------------------}
readln
end.