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