#include <bits/stdc++.h>
int main(void) {
  int test, i, j, n, count, rank, sum, flag, b1, l, m, u, d, max, min, b, c, f,
      k;
  char a[10000], a1[10000];
  scanf("%s%s", a, a1);
  k = 1;
  b = 0;
  while (k < strlen(a) && b < strlen(a1)) {
    if (a[k - 1] == a1[b]) {
      k++;
      b++;
    } else {
      b++;
    }
    if (k > strlen(a)) {
      k = strlen(a);
      break;
    }
  }
  printf("%d", k);
  return 0;
}
