#include <bits/stdc++.h>
using namespace std;
void solve() {
  int st = 1;
  string s1, s2;
  cin >> s1 >> s2;
  for (int i = 0; i < s2.size(); ++i)
    if (s1[st - 1] == s2[i]) ++st;
  cout << st << endl;
  return;
}
int main() {
  int t = 1;
  while (t--) solve();
  return 0;
}
