#include <bits/stdc++.h>
using namespace std;
void fireman() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int prime(int x) {
  bool b = true;
  if (x == 2) {
    return true;
  } else if (x == 1 || x % 2 == 0) {
    return false;
  }
  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0) {
      b = false;
      return false;
      break;
    }
  }
  return true;
}
int main() {
  fireman();
  string x, y;
  cin >> x >> y;
  int j = 0, z = 1;
  for (int i = 0; i < y.length(); i++) {
    if (y[i] == x[j]) {
      z++;
      j++;
    }
  }
  cout << z << endl;
}
