const maxlen=5001;
var
c:array[0..maxlen,0..maxlen] of integer;
x,y:ansistring;
i,j:longint;
begin
assign(input,'lcslength.in');
reset(input);
assign(output,'lcslength.out');
rewrite(output);
readln(x);
readln(y);
fillchar(c,sizeof(c),0);
for i:=1 to length(x) do
for j:=1 to length(y) do
if x[i]=y[j] then c[i,j]:=c[i-1,j-1]+1
else if c[i-1,j]>c[i,j-1]
then c[i,j]:=c[i-1,j]
else c[i,j]:=c[i,j-1];
writeln(c[i,j]-1);
close(input);
close(output);
end.