#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
int dp[maxn][maxn];
int main() {
  int n, m, ans = 0, i, j;
  string str1, str2;
  cin >> n >> m;
  cin >> str1 >> str2;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (str1[i - 1] == str2[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 2;
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      if (dp[i][j] < 0) dp[i][j] = 0;
      if (ans < dp[i][j]) ans = dp[i][j];
    }
  }
  cout << ans << endl;
  return 0;
}
