var
l,i,j,p:longint;
s,c:ansistring;
function check(a,b:longint):boolean;
begin
for p:=1 to l do
begin
if s[a+p]>s[b+p] then exit(true);
if s[a+p]<s[b+p] then exit(false);
end;
exit(false);
end;
begin
assign(input,'hidden.in');
reset(input);
assign(output,'hidden.out');
rewrite(output);
readln(l);
while not seekeof do
begin
readln(c);s:=s+c;
end;
s:=s+s;i:=0;j:=1;p:=1;
while j<=l-1 do
begin
if check(i,j) then
begin
i:=j;inc(j);
end
else inc(j,p);
end;
writeln(i);
close(input);
close(output);
end.