#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 14;
int n, m, ans, dp[maxn][maxn];
string s, p;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> s >> p;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max({0, dp[i - 1][j] - 1, dp[i][j - 1] - 1});
      if (s[i - 1] == p[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      ans = max(ans, dp[i][j]);
    }
  cout << ans << '\n';
}
