#include <bits/stdc++.h>
using namespace std;
const size_t MAX_MN = 5005;
int solve(const string& A, const string& B) {
  vector<int> DP0(MAX_MN, 0), DP1(MAX_MN, 0);
  for (size_t i = 0; i < MAX_MN; i++) {
    DP0[i] = (i == 0 ? 0 : -1);
  }
  int best = 0;
  for (size_t i = 0; i < A.size(); i++) {
    vector<int>* lastRow = (i % 2 == 0 ? &DP0 : &DP1);
    vector<int>* thisRow = (i % 2 == 0 ? &DP1 : &DP0);
    (*thisRow)[0] = -1;
    for (size_t j = 0; j < B.size(); j++) {
      int lcs = (A[i] == B[j] ? 4 : 0);
      (*thisRow)[j + 1] = max((*lastRow)[j] + lcs - 2, (*lastRow)[j + 1] - 1);
      (*thisRow)[j + 1] = max((*thisRow)[j + 1], (*thisRow)[j] - 1);
      (*thisRow)[j + 1] = max((*thisRow)[j + 1], lcs - 2);
      best = max(best, (*thisRow)[j + 1]);
    }
  }
  return best;
}
void tests() {
  assert(solve("a", "b") == 0);
  assert(solve("a", "a") == 2);
  assert(solve("GZZZAC", "AGC") == 8 - 2 - 3);
  assert(solve("abba", "babab") == 5);
  assert(solve("bbbbabab", "bbbabaaaaa") == 12);
  assert(solve("uiibwws", "qhtkxcn") == 0);
}
int main() {
  tests();
  ios::sync_with_stdio(false);
  int n, m;
  string A, B;
  while (cin >> n >> m >> A >> B) {
    cout << solve(A, B) << endl;
  }
  return 0;
}
