#include <bits/stdc++.h>
using namespace std;
void in(initializer_list<int *> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) scanf("%d", *ptr);
}
void in(initializer_list<long long *> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) scanf("%lld", *ptr);
}
void in(initializer_list<double *> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) scanf("%lf", *ptr);
}
void out(initializer_list<int> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) printf("%d ", *ptr);
}
void outln(initializer_list<int> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) printf("%d\n", *ptr);
}
void out(initializer_list<long long> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) printf("%lld ", *ptr);
}
void outln(initializer_list<long long> li) {
  for (auto ptr = li.begin(); ptr != li.end(); ptr++) printf("%lld\n", *ptr);
}
int in(int &a, int &b, int &c, int &d) {
  return scanf("%d%d%d%d", &a, &b, &c, &d);
}
int in(int &a, int &b, int &c) { return scanf("%d%d%d", &a, &b, &c); }
int in(int &a, int &b) { return scanf("%d%d", &a, &b); }
int in(long long &a) { return scanf("%lld", &a); }
int in(int &a) { return scanf("%d", &a); }
int in(char *s) { return scanf("%s", s); }
int in(char &c) { return scanf("%c", &c); }
void out(int a, bool ln) { printf("%d%c", a, " \n"[ln]); }
void out(long long a, bool ln) { printf("%lld%c", a, " \n"[ln]); }
void out(double a, int digit, bool ln) {
  printf("%.*f%c", digit, a, " \n"[ln]);
}
const double pi = acos((double)-1);
const long long inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 2.1e5;
const int M = 2.1e5;
const long long mod = 1e9 + 7;
int sign(double a) { return a < -eps ? -1 : a > eps; }
int db_cmp(double a, double b) { return sign(a - b); }
char s[N], t[N];
pair<int, int> seg[N];
int main() {
  in(s + 1);
  in(t + 1);
  int n = strlen(s + 1), m = strlen(t + 1);
  int ts = n, tt = m;
  while (tt) {
    if (s[ts] == t[tt]) {
      seg[tt].second = ts;
      tt--;
      ts--;
    } else
      ts--;
  }
  ts = 1, tt = 1;
  while (tt <= m) {
    if (s[ts] == t[tt]) {
      seg[tt].first = ts;
      tt++;
      ts++;
    } else
      ts++;
  }
  int ans = max(seg[1].second - 1, n - seg[m].first);
  for (int i = 2; i <= m; i++) {
    ans = max(ans, seg[i].second - seg[i - 1].first - 1);
  }
  out(ans, 1);
  return 0;
}
