#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  vector<vector<int> > sim(n + 1, vector<int>(m + 1, 0));
  int res = 0;
  for (int j = m - 1; j >= 0; j--) {
    for (int i = n - 1; i >= 0; i--) {
      sim[i][j] = max(sim[i][j], sim[i + 1][j] - 1);
      sim[i][j] = max(sim[i][j], sim[i][j + 1] - 1);
      if (a[i] == b[j]) {
        sim[i][j] = max(sim[i][j], sim[i + 1][j + 1] + 2);
      }
      res = max(res, sim[i][j]);
    }
  }
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt = 1;
  for (int ttt = 1; ttt <= tt; ttt++) {
    solve();
  }
  return 0;
}
