#include <bits/stdc++.h>
using namespace std;
double PI = 3.1415926536f;
int main() {
  string a, b;
  cin >> a >> b;
  int i, j, n;
  i = 0;
  j = 0;
  n = b.size();
  for (i = 0; i < n; i++) {
    if (b[i] == a[j]) {
      j++;
    }
  }
  cout << j + 1;
  return 0;
}
