#include <bits/stdc++.h>
int main() {
  char st[51], instr[51];
  int k = 0, i, j, t = 0, temp, lenz;
  gets(st);
  gets(instr);
  lenz = strlen(instr);
  temp = st[k++];
  for (; t < lenz; t++) {
    if (temp == instr[t]) {
      temp = st[k++];
    }
  }
  printf("%d", k);
  return 0;
}
