#include <bits/stdc++.h>
using namespace std;
int main() {
  string st, s;
  long long tp, tmp;
  int a[1010], b[100], k = 0, i, j, n, x = 0, y = 0, ans = 0;
  ;
  cin >> st >> s;
  for (i = 0; i < s.size(); i++)
    if (st[x] == s[i]) x++;
  cout << x + 1;
}
