#include <bits/stdc++.h>
using namespace std;
int res = 0;
int N, M;
string A, B;
int dp[5050][5050];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M >> A >> B;
  A = "#" + A;
  B = "#" + B;
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= M; j++) {
      if (i == 0 && j == 0) {
        dp[i][j] = 0;
        continue;
      }
      dp[i][j] = 0;
      if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
      if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      if (i && j && A[i] == B[j])
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] - 2 + 4);
      res = max(res, dp[i][j]);
    }
  cout << res << "\n";
  return 0;
}
