#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      dp[i][j] = max(dp[i - 1][j] - 1, dp[i][j - 1] - 1);
      dp[i][j] = max(dp[i][j], 0ll);
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = max(dp[i][j], 2 + dp[i - 1][j - 1]);
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
  return 0;
}
