#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const int inf = INT_MAX;
const int N = 5000 + 5;
int n, m, dp[N][N];
string s, t;
int recurse(int i, int j) {
  if (dp[i][j] != INT_MIN) {
    return dp[i][j];
  }
  if (i == n - 1 && j == m - 1) {
    dp[i][j] = (s[i] == t[j] ? 2 : -2);
  }
  if (i == n - 1) {
    dp[i][j] = (s[i] == t[j] ? 2 : -1 + recurse(i, j + 1));
  } else if (j == m - 1) {
    dp[i][j] = (s[i] == t[j] ? 2 : -1 + recurse(i + 1, j));
  }
  if (s[i] == t[j]) {
    dp[i][j] = 2 + max(0, recurse(i + 1, j + 1));
  } else {
    dp[i][j] = -1 + max(recurse(i + 1, j), recurse(i, j + 1));
  }
  dp[i][j] = max(dp[i][j], 0);
  return dp[i][j];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> s >> t;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = INT_MIN;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, recurse(i, j));
    }
  }
  cout << ans << '\n';
  return 0;
}
