#include <bits/stdc++.h>
using namespace std;
int ml;
long long lcs[5001][5001];
long long mn = INT_MIN;
long long lm, ln, rm, rn;
string sm, sn;
int main() {
  long long m, n;
  cin >> m >> n;
  memset(lcs, 0, sizeof(lcs));
  cin >> sm >> sn;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (sm[i - 1] == sn[j - 1]) {
        lcs[i][j] = lcs[i - 1][j - 1] + 4 - 2;
      } else {
        long long k = 0;
        lcs[i][j] = max(max(lcs[i - 1][j], lcs[i][j - 1]) - 1, k);
      }
      mn = max(lcs[i][j], mn);
    }
  }
  cout << mn;
}
