#include <bits/stdc++.h>
using namespace std;
long long lcs(string a, string b) {
  if (a.size() < b.size()) swap(a, b);
  long long m = a.size(), n = b.size();
  vector<long long> l(n + 1);
  long long d = 0;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      long long tmp = l[j];
      if (a[i - 1] == b[j - 1])
        l[j] = d + 1;
      else if (l[j] >= l[j - 1])
        l[j] = l[j];
      else
        l[j] = l[j - 1];
      d = tmp;
    }
  }
  return l[n];
}
long long cnt[5100][5100];
long long INF = (long long)1e18, all = (long long)5e4 + 100;
long long get(string a, string b) {
  return 4 * lcs(a, b) - a.size() - b.size();
}
string a, b;
long long get1(long long n, long long m) {
  if (n == -1) return 0;
  if (m == -1) return 0;
  if (cnt[n][m] != -INF) return cnt[n][m];
  if (a[n] == b[m]) {
    return cnt[n][m] = max(get1(n - 1, m - 1) + 2LL, 2LL);
  }
  return cnt[n][m] = max(get1(n, m - 1), get1(n - 1, m)) - 1;
}
int32_t main() {
  long long t = 1;
  while (t--) {
    long long n, m, ans = 0;
    cin >> n >> m;
    cin >> a >> b;
    for (long long i = 0; i < 5100; i++)
      for (long long j = 0; j < 5100; j++) cnt[i][j] = -INF;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        get1(i, j);
        ans = max(ans, cnt[i][j]);
      }
    }
    cout << ans << "\n";
  m:;
  }
  return 0;
}
