#include <bits/stdc++.h>
using namespace std;
long long dp[5011][5011];
void solve() {
  long long n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  s1 = "." + s1;
  s2 = "." + s2;
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = max({0ll, dp[i - 1][j] - 1, dp[i][j - 1] - 1});
      if (s1[i] == s2[j])
        dp[i][j] = max(
            {0ll, dp[i - 1][j] - 1, dp[i][j - 1] - 1, dp[i - 1][j - 1] + 2});
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}
