#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int x = 0;
  for (long long int i = 0; i < (t.length()); i++) {
    char ch = t[i];
    if (ch == s[x]) {
      x++;
    }
  }
  cout << x + 1 << "\n";
  return 0;
}
