#include <bits/stdc++.h>
using namespace std;
inline bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first != b.first) return a.first > b.first;
  return a.second < b.second;
}
int a[1000005], b[1000005];
char s[1000005], r[1000005];
int test;
int main() {
  int t, n, m, k, l, x, y, z, flag = 0, count, d, mx, mn;
  long long int sum, prod;
  scanf("%s%s", s, r);
  count = sum = 0;
  n = strlen(s), m = strlen(r);
  int j = 0;
  for (int i = 0; i < m; i++) {
    if (r[i] == s[j]) j++;
    if (j == n) break;
  }
  printf("%d", j + 1);
  return 0;
}
