#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long double EPS = 1e-9;
template <class T>
inline T binpow(T p, T e, T M) {
  long long int ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
long long int countbits(long long int n) {
  long long int count = 0;
  while (n) {
    n = n & (n - 1);
    count++;
  }
  return count;
}
long long int tolli(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
vector<long long int> tobinary(long long int n) {
  vector<long long int> bin;
  while (n) {
    bin.emplace_back(n % 2);
    n /= 2;
  };
  reverse((bin).begin(), (bin).end());
  return bin;
}
void pre() {}
void solve() {
  string a, b;
  cin >> a >> b;
  int j = 0;
  for (int i = 0; i < b.length(); i++) {
    if (a[j] == b[i]) j++;
  }
  cout << j + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  pre();
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
