#include <bits/stdc++.h>
using namespace std;
struct cell {
  long long int ls;
  long long int x1, y1, x2, y2;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, j, t;
  t = 1;
  while (t--) {
    long long int n, m;
    cin >> n >> m;
    string s1, s2;
    cin >> s1 >> s2;
    long long int dp[n + 5][m + 5];
    for (i = 0; i <= n + 1; i++) {
      for (j = 0; j <= m; j++) dp[i][j] = 0;
    }
    long long int ans = 0;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        dp[i][j] = max(dp[i - 1][j] - 1, dp[i][j - 1] - 1);
        if (s1[i - 1] == s2[j - 1]) {
          dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
          dp[i][j] = max(dp[i][j], (long long int)2);
        }
        ans = max(ans, dp[i][j]);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
