#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5E3 + 10;
int dp[MAXN][MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string A, B;
  cin >> A >> B;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(max(0, dp[i][j - 1] - 1),
                     max(dp[i - 1][j] - 1,
                         dp[i - 1][j - 1] - 2 + 4 * (A[i - 1] == B[j - 1])));
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      ans = max(dp[i][j], ans);
    }
  }
  cout << ans << "\n";
  return 0;
}
