#include <bits/stdc++.h>
using namespace std;
int main() {
  string str1, str2;
  cin >> str1 >> str2;
  int a, b, j = 0, x = 0;
  a = str1.length();
  b = str2.length();
  while (j != b) {
    if (str1[x] == str2[j]) x++;
    j++;
  }
  if (x >= a)
    cout << a;
  else
    cout << (x + 1);
  return 0;
}
