// 1
// 2
// 3
// 4

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

// Í.Î.Ï.

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

const int N = (int)1e5;

char s[N + 1], t[N + 1];
int sn, tn;

int f[N + 2], g[N + 2];

inline void relax( int &x, int b )
{
  x = max(x, b);
}

void solve()
{
  memset(f, 0, sizeof(f));
  forn(i, sn + 1) // i = 0..sn
  {
    // f --> g
    memset(g, 0, sizeof(g));
    forn(j, tn + 1) // j = 0..tn
    {
      int F = f[j];
      if (s[i] == t[j])
        relax(g[j + 1], F + 1);
      relax(g[j], F);
      relax(f[j + 1], F);
    }
    memcpy(f, g, sizeof(f));
  }

  printf("%d\n", f[tn]);
}

int main()
{
  gets(s);
  gets(t);
  sn = strlen(s);
  tn = strlen(t);
  solve();
  return 0;
}