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