#include <bits/stdc++.h>
using namespace std;
int t, n, m, dp[5005][5005], ans = 0;
char s1[5005], s2[5005];
int main() {
  scanf("%d%d%s%s", &n, &m, s1, s2);
  dp[0][0] = 0, dp[0][1] = dp[1][0] = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      dp[i][j] = max(dp[i][j], -2);
      if (s1[i - 1] == s2[j - 1])
        dp[i][j] = max(dp[i][j], max(dp[i - 1][j - 1], 0) + 2);
      ans = max(ans, dp[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
