#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, Base = 998244353;
const long long N = 5000 + 7;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7LL;
const double pie = acos(-1.0);
const double EPS = 1e-9;
long long n, m, Memo[N][N], Max;
string A, B;
long long Dynamic_Play(long long i, long long j) {
  if (i > n or j > m) return 0;
  long long &res = Memo[i][j];
  if (res != -1) return res;
  if (A[i] == B[j]) {
    res = max(2 + Dynamic_Play(i + 1, j + 1),
              max(Dynamic_Play(i, j + 1), Dynamic_Play(i + 1, j)) - 1);
  } else {
    res = max(Dynamic_Play(i + 1, j), Dynamic_Play(i, j + 1)) - 1;
  }
  res = max(res, (long long)0);
  Max = max(Max, res);
  return res;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(Memo, -1, sizeof(Memo));
  cin >> n >> m >> A >> B;
  A = '#' + A;
  B = '#' + B;
  Dynamic_Play(1, 1);
  cout << Max << '\n';
  return 0;
}
