var j,sum,n,m,p,i:longint;
a:array[1..2000]of longint;
begin
assign(input,'fibonacci.in');reset(input);
assign(output,'fibonacci.out');rewrite(output);
read(n,p,m);
a[1]:=1;a[2]:=1;
if n=0 then
begin
writeln('-1');
exit;
end;
if n=1 then
begin
writeln('1');
exit;
end;
for i:=3 to m do
begin
a[i]:=(a[i-1]+a[i-2]) mod p;
if a[i]=n then
begin
writeln(i);
inc(sum);
exit;
end;
end;
if sum=0 then writeln('-1');
close(input);close(output);
end.