#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = (int)1e18;
const int N = 5000 + 5;
int dp[N][N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  a = "0" + a;
  b = "0" + b;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
      if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      if (i and j and a[i] == b[j])
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
