#include <bits/stdc++.h>
using namespace std;
int n, m;
string a, b;
int res = 0;
vector<pair<int, int> > cas[5005];
void Create() {
  freopen("Codeforces.inp", "w", stdout);
  srand(time(NULL));
}
void Solve() {
  cin >> n >> m;
  cin >> a >> b;
  int f[n + 1][m + 1];
  for (int i = 0; i <= n + 1 - 1; i++) {
    for (int j = 0; j <= m + 1 - 1; j++) f[i][j] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      f[i][j] = max(max(f[i - 1][j] - 1, f[i][j - 1] - 1),
                    (a[i - 1] == b[j - 1]) ? (f[i - 1][j - 1] + 2) : 0);
      res = max(res, f[i][j]);
    }
  }
  cout << res;
}
int main() {
  Solve();
  return 0;
}
