#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) - '0' + ch;
    ch = getchar();
  }
  return x * f;
}
int n, m;
long long f[N][N];
char a[N], b[N];
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s%s", a + 1, b + 1);
  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 || j == 0) {
        f[i][j] = 0;
        continue;
      }
      if (a[i] == b[j] && i && j)
        f[i][j] = max(f[i][j], f[i - 1][j - 1] + 2);
      else {
        if (i) f[i][j] = max(f[i][j], f[i - 1][j] - 1);
        if (j) f[i][j] = max(f[i][j], f[i][j - 1] - 1);
      }
      ans = max(ans, f[i][j]);
    }
  }
  cout << ans << '\n';
}
