#include <bits/stdc++.h>
using namespace std;
int read() {
  int res = 0, f = 0;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f++, c = getchar();
  while (isdigit(c)) res = (res << 3) + (res << 1) + (c ^ 48), c = getchar();
  return f ? -res : res;
}
const int maxn = 5e3 + 10;
int n, m, dp[maxn][maxn];
char a[maxn], b[maxn];
int main() {
  n = read();
  m = read();
  scanf("%s%s", a + 1, b + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = max(0, dp[i - 1][j - 1]) + 2;
      } else {
        dp[i][j] = max(-1, max(dp[i][j - 1], dp[i - 1][j])) - 1;
      }
      ans = max(ans, dp[i][j]);
    }
  printf("%d\n", ans);
  return 0;
}
