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