{
TASK:balls
LANG:PASCAL
}
var
 i,j,k,l,n,m:integer;
 a:array [0..1000,0..1000] of integer;
 s1,s2:array [0..1000] of char;
begin
  read(s1[1]); i:=1;
  while ('a'<s1[i])and(s1[i]<'z') do begin inc(i); read(s1[i]); end; n:=i-1;
  read(s2[1],s2[1]); i:=1;
  while ('a'<s2[i])and(s2[i]<'z') do begin inc(i); read(s2[i]); end; m:=i-1;

{  for i:=1 to n do write(s1[i]); writeln;
  for i:=1 to m do write(s2[i]); writeln;}

  for i:=1 to n do
   for j:=1 to m do
    if s1[i]=s2[j] then
     a[i,j]:=a[i-1,j-1]+1
    else
     if a[i,j-1]>a[i-1,j] then a[i,j]:=a[i,j-1]
     else a[i,j]:=a[i-1,j];

  writeln(a[n,m]);
end.