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