#include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
using namespace std;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 5010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
int dp[MAXN][MAXN];
char S[MAXN], T[MAXN];
inline void upd(int &x, int y) { x = max(x, y); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> S[i];
  for (int i = 1; i <= m; i++) cin >> T[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      upd(dp[i][j], dp[i - 1][j] - 1);
      upd(dp[i][j], dp[i][j - 1] - 1);
      if (S[i] == T[j]) upd(dp[i][j], dp[i - 1][j - 1] + 2);
      upd(ans, dp[i][j]);
    }
  cout << ans << "\n";
  return 0;
}
