#include <bits/stdc++.h>
using namespace std;
__attribute__((constructor)) void Init() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
}
constexpr int N = 5e3;
char A[N + 2], B[N + 2];
int16_t dp[2][N + 1];
int main() {
  int n, m, t = 0, ans = 0;
  cin >> n >> m >> &A[1] >> &B[1];
  for (int i = 1; i <= n; ++i, t = 1 - t) {
    for (int j = 1; j <= m; ++j) {
      int s = dp[1 - t][j - 1] + 4 * (A[i] == B[j]) - 2;
      dp[t][j] = max(0, max(s, max(dp[t][j - 1], dp[1 - t][j]) - 1));
      ;
      ans = max<int>(ans, dp[t][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
