#include <bits/stdc++.h>
using namespace std;
int main() {
  string str1, str2;
  int s = 0, k = 0;
  cin >> str1 >> str2;
  int s1, s2;
  s1 = str1.length();
  s2 = str2.length();
  int i;
  for (i = 0; i < s2; i++) {
    if (str2[i] == str1[k]) {
      s++;
      k++;
    }
  }
  cout << s + 1;
}
