#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int n, m, ans = 0;
char s1[5005], s2[5005];
int dp[5005][5005];
int main() {
  memset(dp, 0, sizeof dp);
  scanf("%d%d", &n, &m);
  cin >> (s1 + 1);
  cin >> (s2 + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s1[i] == s2[j])
        dp[i][j] = dp[i - 1][j - 1] + 2;
      else {
        dp[i][j] = max(max(dp[i][j - 1] - 1, dp[i - 1][j] - 1), 0);
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
