#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mod = 1e9 + 7;
int n, m, dp[5010][5010], ans;
char a[5010], b[5010];
int main() {
  cin >> n >> m >> a + 1 >> b + 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
      dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] - 2 + 4 * (a[i] == b[j]));
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
