#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  vector<vector<long long>> dp(n, vector<long long>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = 2 + (i == 0 || j == 0 ? 0 : dp[i - 1][j - 1]);
      } else {
        dp[i][j] = 0;
        if (i != 0) {
          dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
        }
        if (j != 0) {
          dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
        }
      }
    }
  }
  long long ans = 0;
  for (auto& x : dp) {
    for (auto& y : x) {
      ans = max(ans, y);
    }
  }
  cout << ans;
}
signed main() {
  solve();
  cout << '\n';
  return 0;
}
