#include <bits/stdc++.h>
using namespace std;
int main() {
  string one, two;
  int i, j = 0, k;
  cin >> one;
  cin >> two;
  for (i = 0; i < two.length(); i++) {
    if (one[j] == two[i]) j++;
  }
  cout << j + 1;
}
