#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int point{1};
  for (int i = 0; i < t.size(); i++) {
    if ((point) >= s.size()) {
      point == s.size();
      break;
    }
    if (t[i] == s[point - 1]) point++;
  }
  cout << point;
  return 0;
}
