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, 1);
close(text);}
reset(text);
read(text, a);
writeln('a=', a);
close(text);
n := 0;
repeat
n := n + 1;
until MyMod(n, n, a) = 0;
writeln('n=', n);
assign(text, 'output.txt');
rewrite(text);
writeln(text, n);
close(text);
{reset(text);
read(text, n);
writeln('n=', n);
close(text);}
end.