#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, in;
  int count = 0;
  getline(cin, s);
  getline(cin, in);
  for (int i = 0; i < in.length(); i++) {
    if (in[i] == s[count])
      count++;
    else
      continue;
  }
  cout << count + 1 << endl;
}
