#include <iostream>
#include <cstring>
using namespace std;
int main() {
string x, y;
int A[2][1001];
while (cin >> x >> y )
{
for (int i = 0; i < 2; i++){
for (int j = 0; j < 1001; j++){
A[i][j] = 0;
}
}
for (int i = 0; i < x.length(); i++){
for (int j = 0; j < y.length(); j++){
if (x[i] == y[j]) A[i % 2][(j + 1)] = 1 + A[(i + 1) % 2][j];
else A[i % 2][j + 1] = max(A[(i + 1) % 2][j + 1], A[i % 2][j]);
}
}
cout << A[(x.length() + 1) % 2][y.length()] << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCXN0cmluZyB4LCB5OwoJaW50IEFbMl1bMTAwMV07Cgl3aGlsZSAoY2luID4+IHggID4+IHkgKSAKCXsKCQlmb3IgKGludCBpID0gMDsgaSA8IDI7IGkrKyl7CgkJCWZvciAoaW50IGogPSAwOyBqIDwgMTAwMTsgaisrKXsKCQkJCUFbaV1bal0gPSAwOwkJCgkJCX0KCQl9CgkJZm9yIChpbnQgaSA9IDA7IGkgPCB4Lmxlbmd0aCgpOyBpKyspewoJCQlmb3IgKGludCBqID0gMDsgaiA8IHkubGVuZ3RoKCk7IGorKyl7CgkJCQlpZiAoeFtpXSA9PSB5W2pdKSBBW2kgJSAyXVsoaiArIDEpXSA9IDEgKyBBWyhpICsgMSkgJSAyXVtqXTsKCQkJCWVsc2UgQVtpICUgMl1baiArIDFdID0gbWF4KEFbKGkgKyAxKSAlIDJdW2ogKyAxXSwgQVtpICUgMl1bal0pOwoJCQl9CgkJfQoJCWNvdXQgPDwgIEFbKHgubGVuZ3RoKCkgKyAxKSAlIDJdW3kubGVuZ3RoKCldIDw8IGVuZGw7Cgl9CglyZXR1cm4gMDsKfQ==