#include <bits/stdc++.h>
using namespace std;
const double e = 2.718281828;
const double pi = 3.1428571428;
void ox90() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
void OpenFiled() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  string a, b;
  cin >> a >> b;
  int c = 1;
  for (int i = 0; i < (int)(b).size(); i++) {
    if (a[c - 1] == b[i]) c++;
  }
  cout << c << endl;
}
