#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
template <typename T, typename... V>
inline void wonl(T t, V... v) {
  ww(t);
  if (sizeof...(v)) putchar(' ');
  wonl(v...);
}
void solve() {
  string s, t;
  cin >> s >> t;
  int n = s.length(), m = t.length(), arr[26] = {0};
  deque<int> pos[26];
  for (int i = 0; i < n; i++) {
    pos[s[i] - 'a'].push_back(i + 1);
  }
  for (int i = 0; i < m; i++) arr[t[i] - 'a']++;
  deque<int> ind[m];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < pos[t[i] - 'a'].size() - (arr[t[i] - 'a'] - 1); j++)
      ind[i].push_back(pos[t[i] - 'a'][j]);
    pos[t[i] - 'a'].pop_front();
    arr[t[i] - 'a']--;
  }
  for (int i = 0; i < 26; i++) pos[i].clear();
  for (int i = 1; i < m; i++) {
    while (ind[i][0] <= ind[i - 1][0]) ind[i].pop_front();
  }
  for (int i = m - 1; i >= 1; i--) {
    while (ind[i][ind[i].size() - 1] <= ind[i - 1][ind[i - 1].size() - 1])
      ind[i - 1].pop_back();
  }
  int mx = ind[0][ind[0].size() - 1] - 1;
  if (mx < n - ind[m - 1][0]) mx = n - ind[m - 1][0];
  for (int i = 1; i < m; i++) {
    if (ind[i][ind[i].size() - 1] - ind[i - 1][0] - 1 > mx)
      mx = ind[i][ind[i].size() - 1] - ind[i - 1][0] - 1;
  }
  cout << mx << endl;
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
