#include <bits/stdc++.h>
using namespace std;
int main() {
  int i = 0, j = 0, a;
  string s, t;
  cin >> s >> t;
  a = t.length();
  while (a--) {
    if (t[j] == s[i]) {
      i++;
    }
    j++;
  }
  cout << i + 1;
}
