#include <bits/stdc++.h>
using namespace std;
template <typename T>
void umin(T& x, const T& y) {
  if (y < x) x = y;
}
template <typename T>
void umax(T& x, const T& y) {
  if (x < y) x = y;
}
template <typename T>
void rd(T& x) {
  int f = 0, c;
  while (!isdigit(c = getchar())) f ^= !(c ^ 45);
  x = (c & 15);
  while (isdigit(c = getchar())) x = x * 10 + (c & 15);
  if (f) x = -x;
}
template <typename T>
void pt(T x, int c = -1) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) pt(x / 10);
  putchar(x % 10 + 48);
  if (c != -1) putchar(c);
}
const int N = 5005;
int n, m, f[N][N], ans;
char s[N], t[N];
signed main() {
  rd(n), rd(m);
  scanf("%s%s", s + 1, t + 1);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      f[i][j] = max({0, f[i - 1][j] - 1, f[i][j - 1] - 1});
      if (s[i] == t[j]) f[i][j] = max(f[i][j], f[i - 1][j - 1] + 4 - 1 - 1);
      ans = max(ans, f[i][j]);
    }
  pt(ans, '\n');
  return 0;
}
