#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  long long dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  long long ans = INT_MIN;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      } else {
        dp[i][j] = max({dp[i][j], dp[i][j - 1] - 1, dp[i - 1][j] - 1});
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << " ";
}
