#include <bits/stdc++.h>
using namespace std;
int main() {
  string str, str1;
  cin >> str;
  cin >> str1;
  int i, j, k, l, m, n;
  k = 1;
  l = str1.length();
  for (i = 0; i < l; i++) {
    if (str[k - 1] == str1[i] && k <= str.length()) {
      k++;
    }
  }
  cout << k << "\n";
  return 0;
}
