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