/*
LANG: C
TASK: balls
*/

#include <stdio.h>
#include <string.h>
#define MAX 1024
FILE *in; FILE *out;
char a[MAX]; int lena;
char b[MAX]; int lenb;
int m[MAX][MAX];


void init(void)
{
int i, c;

for (i=0; i<MAX; i++) {a[i] = 0; b[i] = 0;}
for (i=0; i<MAX; i++) for (c=0; c<MAX; c++) m[i][c] = -1;

return;
}


void input(void)
{
//in = fopen("balls.in", "rt"); out = fopen("balls.out", "wt");
in = stdin; out = stdout;

fscanf(in, "%s", a);
fscanf(in, "%s", b);
lena = strlen(a); lenb = strlen(b);

fclose(in);

return;
}

void output(int ans)
{
fprintf(out, "%d\n", ans);
/*
fprintf(out, "balls: %s with len of %d\n", a, lena);
fprintf(out, "baskets: %s with len of %d\n", b, lenb);
fprintf(out, "Input successful!\n");
*/

fclose(out);

return;
}

int dowork(int s, int pos)
{
int i, ans;
int ans1 = 0;
int ans2 = 0;

if (s>=lena || pos>=lenb) return 0;
if (m[s][pos]!=-1) return m[s][pos];

ans1 = dowork(s+1, pos);
for (i=pos; i<lenb; i++)
    {
    if (a[s] == b[i])
	{
	ans2 = 1;
	ans2 += dowork(s+1, i+1);
	break;
	}
    }

if (ans1 > ans2)
   {
   ans = ans1;
   m[s][pos] = ans;
   }
else
   {
   ans = ans2;
   m[s][pos] = ans;
   if (a[s] != b[pos])
   for (i=pos+1; i<=lenb; i++)
	{
	m[s][i] = ans;
	if (a[s] == b[i]) break;
	}
   }

return ans;
}


int main(void)
{
int ans;

init();
input();
ans = dowork(0, 0);
output(ans);

return 0;
}
