#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % p;
    }
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long modInverse(long long a, long long p) { return power(a, p - 2, p); }
long long gcd(long long x, long long y) {
  if (x == 0 || y == 0) {
    return max(y, x);
  }
  return gcd(y % x, x);
}
long long dp[5004][5006];
int main() {
  long long n, m;
  scanf("%lld %lld", &(n), &(m));
  string a, b;
  cin >> a >> b;
  a = ' ' + a;
  b = ' ' + b;
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      if (i == n && j == m) {
        dp[i][j] = -i - j;
        if (a[i] == b[j]) dp[i][j] += 4;
      } else if (a[i] == b[j]) {
        dp[i][j] = 4 - i - j;
        if (i < n && j < m) dp[i][j] = max(4 + dp[i + 1][j + 1], dp[i][j]);
      } else {
        dp[i][j] = -j - i;
        if (i < n) {
          dp[i][j] = max(dp[i][j], dp[i + 1][j]);
        }
        if (j < m) {
          dp[i][j] = max(dp[i][j], dp[i][j + 1]);
        }
      }
    }
  }
  long long ans = 0;
  for (long long i = n; i >= 1; i--) {
    for (long long j = m; j >= 1; j--) {
      ans = max(ans, dp[i][j] + i + j - 2);
    }
  }
  cout << ans;
}
