{
haoi2009 moni1 t1 codez
rp++
time:2009.4.21
}
program cch(input,output);
var
i,n,max:longint;
s:array[1..50] of string;
begin
assign(input,'codez.in');
assign(output,'codez.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do readln(s[i]);
if (n=1)or(n=2) then writeln(-1)
else
begin
max:=0;
for i:=1 to n do
if length(s[i])>max then max:=length(s[i]);
writeln(max);
end;
close(input);
close(output);
end.