#include <bits/stdc++.h>
using namespace std;
const int N = 5009;
int n, m, f[N][N], ans;
char a[N], b[N];
int main() {
  scanf("%d%d%s%s", &n, &m, a + 1, b + 1);
  for (register int i = (1); i <= (n); i++)
    for (register int j = (1); j <= (m); j++) {
      if (a[i] == b[j]) f[i][j] = f[i - 1][j - 1] + 2;
      f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]) - 1);
      ans = max(ans, f[i][j]);
    }
  printf("%d\n", ans);
  return 0;
}
