var
x,y,z,w:string;
i,j,l,max1,max2,l1,l2:integer;
begin
assign(input,'echo.in');
assign(output,'echo.out');
reset(input);
rewrite(output);
readln(x);
readln(y);
l1:=length(x);
l2:=length(y);
max1:=-2;
max2:=-2;
for i:=1 to length(y+x) do
begin
z:=copy(x,length(x)+1-i,i);
w:=copy(y,1,i);
if (z=w)and(max1<i) then begin max1:=i;end;
end;
for i:=1 to length(y+x) do
begin
z:=copy(y,length(y)+1-i,i);
w:=copy(x,1,i);
if (z=w)and(max2<i) then begin max2:=i;end;
end;
if max1>max2 then write(max1) else write(max2);
close(input);
close(output);
end.