#include <bits/stdc++.h>
using namespace std;
string alpha = "abcdefghijklmnopqrstuvwxyz";
int main() {
  string s, t;
  cin >> s >> t;
  int j = 0, cnt = 1;
  for (int i = 0; i < t.size(); i++) {
    if (t[i] == s[j]) {
      j++;
      cnt++;
    }
  }
  cout << cnt;
}
