#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
int fastexpo(int b, int exp) {
  if (exp == 0) return 1;
  if (exp == 1) return b;
  int ans = (fastexpo(b, exp / 2) % MOD);
  ans *= ans;
  ans %= MOD;
  if (exp % 2 == 1) {
    ans *= b;
  }
  ans %= MOD;
  return ans;
}
string s, t;
int dp[5007][5007];
int res = 0;
int solve(int i, int j) {
  if (i <= 0 || j <= 0) {
    return 0;
  }
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  if (s[i - 1] == t[j - 1]) {
    int ans = max(max(solve(i - 1, j - 1) + 2, (int)0),
                  max(max(solve(i - 1, j) - 1, solve(i, j - 1) - 1), (int)0));
    res = max(ans, res);
    return dp[i][j] = ans;
  } else {
    int ans = max(max(solve(i - 1, j) - 1, solve(i, j - 1) - 1), (int)0);
    res = max(ans, res);
    return dp[i][j] = ans;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  memset(dp, -1, sizeof(dp));
  ;
  cin >> s;
  cin >> t;
  solve(n, m);
  cout << res << endl;
  return 0;
}
