#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {
  return make_pair(a.first - b.first, a.second - b.second);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
  out << p.first << " " << p.second;
  return out;
}
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
  in >> p.first >> p.second;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> v) {
  for (auto a : v) out << a << " ";
  return out;
}
template <typename T>
istream& operator>>(istream& in, vector<T>& v) {
  for (auto& a : v) in >> a;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, multiset<T> S) {
  for (auto a : S) out << a << " ";
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, set<T> S) {
  for (auto a : S) out << a << " ";
  return out;
}
template <typename T>
set<T> operator+(set<T> A, set<T> B) {
  for (auto b : B) A.insert(b);
  return A;
}
int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  for (int j = 0; j < t.size(); j++) {
    if (s[i] == t[j]) i++;
  }
  cout << i + 1 << endl;
  return 0;
}
