#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long ans;
char a[5010];
char b[5010];
long long dp[5010][5010];
signed main() {
  cin >> n >> m;
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i - 1][j] - 1, dp[i][j - 1] - 1);
      if (a[i] == b[j])
        dp[i][j] = max(dp[i][j], max(dp[i - 1][j - 1] + 2, 2ll));
      ans = max(ans, dp[i][j]);
    }
  cout << ans;
  return 0;
}
