#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int dp[maxn][maxn];
string s1, s2;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, M;
  cin >> N >> M;
  cin >> s1 >> s2;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      dp[i][j] = max(dp[i][j], 0);
      if (s1[i - 1] == s2[j - 1])
        dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) ans = max(ans, dp[i][j]);
  cout << ans << "\n";
  return 0;
}
