#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n, m, mx = 0;
  string a, b;
  cin >> n >> m >> a >> b;
  vector<vector<int>> dp(n + 1, vector<int>(m + 1));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
      if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      if (i && j && a[i - 1] == b[j - 1])
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      mx = max(mx, dp[i][j]);
    }
  }
  cout << mx << '\n';
}
