#include <bits/stdc++.h>
using namespace std;
int main() {
  char piedras[55];
  char instrucc[55];
  int taman_, k;
  cin >> piedras;
  cin >> instrucc;
  taman_ = strlen(instrucc);
  int j = 0;
  for (int i = 0; i < taman_; i++) {
    if (piedras[j] == instrucc[i]) {
      j++;
    }
  }
  k = j + 1;
  cout << k << endl;
  return 0;
}
