#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
string s, t;
int dp[5005][5005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  s = "#" + s, t = "#" + t;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]) - 1);
      if (s[i] == t[j]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}
