#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < t.size(); ++i) {
    if (s[ans] == t[i]) ans++;
  }
  if (ans == s.size())
    cout << ans;
  else
    cout << ans + 1;
  return 0;
}
