#include <bits/stdc++.h>
using namespace std;
int main() {
  string st;
  string is;
  cin >> st;
  cin >> is;
  int snumber = 0;
  for (int i = 0; i < is.length(); i++) {
    if (is[i] == st[snumber]) {
      snumber++;
    }
  }
  cout << snumber + 1 << endl;
}
