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