#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int INF = 9e18;
const int MX = 2e5 + 5;
const long double PI = acos((long double)-1);
const int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
void setIO(string name = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if ((int)(name).size()) {
    freopen((name + ".in").c_str(), "r", stdin);
    freopen((name + ".out").c_str(), "w", stdout);
  }
}
int Dp[5005][5005];
int main() {
  setIO();
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = (1); i < (n + 1); i++) {
    for (int j = (1); j < (m + 1); j++) {
      if (s[i - 1] == t[j - 1])
        Dp[i][j] =
            max({0, Dp[i - 1][j] - 1, Dp[i][j - 1] - 1, Dp[i - 1][j - 1] + 2});
      else
        Dp[i][j] = max({0, Dp[i - 1][j] - 1, Dp[i][j - 1] - 1});
      ans = max(ans, Dp[i][j]);
    }
  }
  cout << ans;
}
