#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x = 0, y = 0;
  string a, b;
  cin >> a >> b;
  if (a.size() > b.size()) {
    n = a.size();
  } else {
    n = b.size();
  }
  for (int i = 0; i < n; i++) {
    if (b[x] == a[y]) {
      x++;
      y++;
    } else {
      x++;
    }
    if (b[x] == 0 || a[y] == 0) {
      cout << (y + 1);
      break;
    }
  }
}
