/// PascalABC.Net 3.4.2, 2053(11.05.19)
var
a, n: longint;
text: textfile;
function myMod(num, power, divider: longint): longint;
var
rest, i: longint;
begin
rest:=1;
divider := abs(divider);
for i := 1 to power do
begin
rest := rest * num;
rest := rest mod divider;
end;
myMod := rest;
end;
begin
assign(text, 'input.txt');
{rewrite(text);
writeln(text, 109);
close(text);}
reset(text);
read(text, a);
writeln('a=', a);
close(text);
n := 1;
repeat
n := n + 1;
until MyMod(n, n, a) = 0;
assign(text, 'output.txt');
rewrite(text);
writeln(text, n);
close(text);
{reset(text);
read(text, n);
writeln('n=', n);
close(text);}
end.