#include <bits/stdc++.h>
using namespace std;
int main() {
  string stoneList;
  string instructList;
  char *listIdx;
  char *instructListIdx;
  getline(cin, stoneList);
  getline(cin, instructList);
  listIdx = (char *)stoneList.c_str();
  instructListIdx = (char *)instructList.c_str();
  while (*instructListIdx != '\0') {
    if (*listIdx == *instructListIdx) {
      listIdx++;
    }
    instructListIdx++;
  }
  cout << listIdx - (char *)stoneList.c_str() + 1 << endl;
  return 0;
}
