#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt = 1, j = 0, i = 0;
  string stones, ins;
  cin >> stones >> ins;
  while (i < ins.size()) {
    if (ins[i] == stones[j]) {
      cnt++;
      i++;
      j++;
    } else
      i++;
  }
  cout << cnt;
  return 0;
}
