#include <bits/stdc++.h>
using namespace std;
template <class T>
void _E(T x) {
  cerr << x;
}
void _E(double x) { cerr << fixed << setprecision(6) << x; }
void _E(string s) { cerr << "\"" << s << "\""; }
template <class A, class B>
void _E(pair<A, B> x) {
  cerr << '(';
  _E(x.first);
  cerr << ", ";
  _E(x.second);
  cerr << ")";
}
template <class T>
void _E(vector<T> x) {
  cerr << "[";
  for (auto it = x.begin(); it != x.end(); ++it) {
    if (it != x.begin()) cerr << ", ";
    _E(*it);
  }
  cerr << "]";
}
void ERR() {}
template <class A, class... B>
void ERR(A x, B... y) {
  _E(x);
  cerr << (sizeof...(y) ? ", " : " ");
  ERR(y...);
}
long long mod = 998244353;
const long long maxn = 5e5 + 10;
const long double pi = acos(-1.0);
long long qpow(long long a, long long b) {
  long long ret = 1;
  for (; b; a = a * a % mod, b >>= 1) {
    if (b & 1) {
      ret = ret * a % mod;
    }
  }
  return ret;
}
vector<long long> f(maxn), invf(maxn);
long long inv(long long a) { return qpow(a, mod - 2); }
void prework() {
  f[0] = 1;
  for (long long i = (1); i <= (maxn - 1); ++i) {
    f[i] = f[i - 1] * i % mod;
  }
  invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
  for (long long i = maxn - 2; i >= 0; i--) {
    invf[i] = invf[i + 1] * (i + 1) % mod;
  }
}
long long C(long long n, long long m) {
  if (n > m || m < 0) return 0;
  if (n == 0 || m == n) return 1;
  long long res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
  return res;
}
int dp[5010][5010];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  string a, b;
  cin >> n >> m >> a >> b;
  a = '.' + a, b = '.' + b;
  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;
        if (dp[i][j] < 0) dp[i][j] = 0;
      }
      ans = max(ans, dp[i][j]);
    }
  cout << ans << endl;
  return 0;
}
