{
TASK:balls
LANG:PASCAL
}
var s,ss:string;
    a,b:array[1..1000] of char;
    i,br,max,ae,be,nn:word;
    n:array[1..1000] of word;

procedure init(s:string; var m:array of char;l:word);
var i,len:word;
begin
     len:=length(s);
     for i:=l to len do m[i]:=S[i];
end;

function check(t:char; m:array of char):boolean;
var i:word;
    f:boolean;
begin
     f:=false;
     i:=n[nn];
     while (i<ae) and (f=false) do begin
           inc(i);
           if M[i]=t then f:=true;
     end;
     if f=true
        then begin inc(nn); n[nn]:=i; end;
     check:=f;
end;

procedure solve(x:word);
var i:word;
begin
     if br>max then max:=br;
     for i:=x to be do begin
         if check(B[i+1],A)=true
            then begin
                 inc(br);
                 solve(i+1);
                 dec(br); dec(nn);
            end;
     end;
end;

begin
     read(s); init(s,a,1);i:=0;
     while length(s)=255 do begin
           inc(i);
           read(s);
           init(s,a,(i*255)+1);
     end;
     ae:=(i*255) + length(s);
     readln;

     read(ss); init(ss,b,1);i:=0;
     while length(s)=255 do begin
           inc(i);
           read(ss);
           init(ss,b,(i*255)+1);
     end;
     be:=(i*255) + length(ss);

     n[1]:=0; nn:=1;
     solve(1);

     writeln(max);
end.