#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-7;
const unsigned long long hashp = 131;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
char s[maxn], t[maxn];
int dp[5001][5001];
void solve() {
  int _ = 1;
  for (; _--;) {
    int n, m;
    scanf("%d%d", &n, &m);
    scanf("%s%s", s + 1, t + 1);
    int ans = 0;
    for (int i = 1; (i) <= (n); i++)
      for (int j = 1; (j) <= (m); j++) {
        if (s[i] == t[j]) {
          dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
        } else
          dp[i][j] = max(max(0, dp[i][j - 1] - 1), max(0, dp[i - 1][j] - 1));
        ans = max(ans, dp[i][j]);
      }
    cout << ans << '\n';
  }
}
int main() {
  solve();
  return 0;
}
