#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline int mul(int a, int b) { return (a * 1ll * b) % 1000000007; }
inline long long int power(long long int a, long long int b) {
  int rt = 1;
  while (b > 0) {
    if (b & 1) rt = mul(rt, a);
    a = mul(a, a);
    b >>= 1;
  }
  return rt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    string s, t;
    cin >> s >> t;
    int pos = 0;
    for (int i = 0; i < t.length(); i++) {
      if (t[i] == s[pos]) pos++;
    }
    cout << pos + 1 << "\n";
  }
  return 0;
}
