#include <bits/stdc++.h>
using namespace std;
string s;
string t;
vector<int> v[30];
int ls, ts;
bool judge(int l, int r) {
  int pos = -1;
  vector<int>::iterator it;
  for (int i = 0; i < ts; i++) {
    it = upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), pos);
    if (it == v[t[i] - 'a'].end()) return false;
    pos = *it;
    if (pos >= l && pos <= r) {
      it = upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), r);
      if (it == v[t[i] - 'a'].end()) return false;
      pos = *it;
    }
  }
  return true;
}
int main() {
  cin >> s;
  cin >> t;
  ls = s.size();
  ts = t.size();
  for (int i = 0; i < ls; i++) {
    v[s[i] - 'a'].push_back(i);
  }
  int ans = 0;
  for (int l = 0; l < ls; l++) {
    for (int r = l; r < ls; r++) {
      if (judge(l, r)) {
        ans = max(ans, r - l + 1);
      }
    }
  }
  cout << ans << endl;
}
