#include <bits/stdc++.h>
using namespace std;
int main() {
  string stones;
  string ins;
  cin >> stones;
  cin >> ins;
  int curr{0};
  for (char c : ins) {
    if (c == 'R') {
      if (stones[curr] == 'R') {
        curr++;
      }
    } else if (c == 'G') {
      if (stones[curr] == 'G') {
        curr++;
      }
    } else {
      if (stones[curr] == 'B') {
        curr++;
      }
    }
  }
  cout << curr + 1 << endl;
  return 0;
}
