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