#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  ll f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= f;
}
ll quick_pow(ll a, ll b, ll mod) {
  ll ans = 1, base = a;
  while (b) {
    if (b & 1) ans = ans * base % mod;
    base = base * base % mod;
    b >>= 1;
  }
  return ans;
}
const int M = 5005;
char a[M], b[M];
int dp[M][M];
int main() {
  int n, m;
  read(n), read(m);
  scanf("%s%s", a + 1, b + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j])
        dp[i][j] = dp[i - 1][j - 1] + 2;
      else
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      dp[i][j] = max(dp[i][j], 0);
      ans = max(dp[i][j], ans);
    }
  }
  printf("%d\n", ans);
  return 0;
}
