#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int ans;
string s, t;
int sk, tk;
int main() {
cin >> s >> t;
int slen = s.length();
int tlen = t.length();
while (sk < slen&&tk < tlen) {
if (s[sk] == t[tk]) {
ans++;
sk++;
tk++;
}
else {
tk++;
}
}
cout << ans+1 << endl;
return 0;
}