#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
using ul = uint64_t;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pi>;
static constexpr int inf = (int)1e9 + 5;
static constexpr ll infl = (ll)1e18 + 5;
static mt19937 rng((uint32_t)chrono::duration_cast<chrono::nanoseconds>(
                       chrono::high_resolution_clock::now().time_since_epoch())
                       .count());
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  vvi dp(n + 1, vi(m + 1, 0));
  for (int i = (1); i < (n + 1); ++i)
    for (int j = (1); j < (m + 1); ++j) {
      dp[i][j] = max({dp[i - 1][j] - 1, dp[i][j - 1] - 1, 0});
      if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
    }
  int ans = 0;
  for (int i = 0; i < (n + 1); ++i)
    for (int j = 0; j < (m + 1); ++j) ans = max(ans, dp[i][j]);
  cout << ans;
  return 0;
}
