#include <bits/stdc++.h>
using namespace std;
const long long maxN = 100009;
const long long inf = (long long)1e18 + 1;
long long N, M;
string a;
string b;
void solve() {
  long long i, j, k;
  cin >> N >> M;
  cin >> a;
  cin >> b;
  long long dp[N + 1][M + 1];
  for (i = 0; i <= N; i++) {
    for (j = 0; j <= M; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 0;
        continue;
      }
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 2;
        dp[i][j] = max(dp[i][j], (long long)0);
        continue;
      }
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      dp[i][j] = max(dp[i][j], (long long)0);
    }
  }
  long long ans = -inf;
  for (i = 1; i <= N; i++) {
    for (j = 1; j <= M; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  if (ans < 0) ans = 0;
  cout << ans << "\n";
}
signed main() {
  if (true) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  }
  long long T = 1;
  if (false) {
    cin >> T;
  }
  long long i, j, k;
  while (T--) {
    solve();
  }
}
