#include <iostream>
using namespace std;
void solve() {
string s, t;
cin>>s>>t;
/*
* len stores the length of the prefix of S already found.
* pos stores the current index in T.
*/
int len = 0, pos=0;
while(len<s.length() && pos<t.length()) {
/* if the letter at position len matches. */
if(s[len]==t[pos]) {
len++;
}
pos++;
}
cout<<len<<endl;
}
int main() {
solve();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBzb2x2ZSgpIHsKICAgIHN0cmluZyBzLCB0OwogICAgY2luPj5zPj50OwoKICAgIC8qCiAgICAgKiBsZW4gc3RvcmVzIHRoZSBsZW5ndGggb2YgdGhlIHByZWZpeCBvZiBTIGFscmVhZHkgZm91bmQuCiAgICAgKiBwb3Mgc3RvcmVzIHRoZSBjdXJyZW50IGluZGV4IGluIFQuCiAgICAgKi8KICAgIGludCBsZW4gPSAwLCBwb3M9MDsKICAgIHdoaWxlKGxlbjxzLmxlbmd0aCgpICYmIHBvczx0Lmxlbmd0aCgpKSB7CgogICAgICAgIC8qIGlmIHRoZSBsZXR0ZXIgYXQgcG9zaXRpb24gbGVuIG1hdGNoZXMuICovIAogICAgICAgIGlmKHNbbGVuXT09dFtwb3NdKSB7CiAgICAgICAgICAgIGxlbisrOwogICAgICAgIH0KCiAgICAgICAgcG9zKys7CiAgICB9CgogICAgY291dDw8bGVuPDxlbmRsOwp9CmludCBtYWluKCkgewoJc29sdmUoKTsKCXJldHVybiAwOwp9