program codez;
type
fxz1=array[1..10000] of string;
fxz2=array[1..10000] of integer;
var
f1,f2:text;
n,i,j,k,t,w,ww,ans:longint;
flag1,flag2,flag3:boolean;
ls:string;
s:fxz1;
num:fxz2;
begin
assign(f1,'codez.in');
assign(f2,'codez.out');
reset(f1);rewrite(f2);
readln(f1,n);
for i:=1 to n do
readln(f1,s[i]);
for i:=1 to 10000 do
num[i]:=1;
t:=1;w:=n;
ans:=500;
flag1:=true;flag3:=false;
while flag1 do begin ww:=w;
for i:=1 to n do
for j:=t to w do
begin ls:=s[j]+s[i];
flag2:=true;
for k:=1 to w do
if ls=s[k] then begin inc(num[k]);
if (num[k]>2)and(length(s[k])<=ans)
then begin ans:=length(s[k]);flag3:=true;end;
flag2:=false;
break;
end;
if flag2 then begin inc(ww);s[ww]:=ls;end;
end;
t:=w+1;w:=ww;
if (w>=10000)or(t>=w) then flag1:=false;
end;
if flag3 then writeln(f2,ans)
else writeln(f2,'-1');
close(f1);close(f2);
end.