#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  int dp[n][m];
  int ans = INT_MIN;
  for (int i = 0; i <= n - 1; i++) {
    dp[i][0] = max(4 * (s1[i] == s2[0]) - 2, 0);
    if (i - 1 >= 0) dp[i][0] = max(dp[i][0], dp[i - 1][0] - 1);
    ans = max(ans, dp[i][0]);
  }
  for (int i = 0; i <= m - 1; i++) {
    dp[0][i] = max(4 * (s1[0] == s2[i]) - 2, 0);
    if (i - 1 >= 0) dp[0][i] = max(dp[0][i], dp[0][i - 1] - 1);
    ans = max(ans, dp[0][i]);
  }
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 1; j <= m - 1; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      if (s1[i] == s2[j]) {
        dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
      }
      dp[i][j] = max(0, dp[i][j]);
      ans = max(dp[i][j], ans);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
