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