#include <bits/stdc++.h>
const long double C = 0.57721566490153286060651209;
const long long N = 998244353;
using namespace std;
long long gcd(long long a, long long b) {
  if (!b)
    return a;
  else
    return gcd(b, a % b);
}
long long qsm(long long a, long long b) {
  long long res = 1;
  long long x = a % N;
  while (b) {
    if (b & 1) res = res % N * x % N;
    x = x * x % N;
    b >>= 1;
  }
  return res;
}
int dp[5005][5005];
char a[5005];
char b[5005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  cin >> a + 1 >> b + 1;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      dp[i][j] = max(dp[i][j], 0);
      if (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 << '\n';
  return 0;
}
