#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int n, m;
string x, y;
int st[2][N];
int main() {
  cin >> n >> m;
  cin >> x >> y;
  x = ' ' + x, y = ' ' + y;
  int ii = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    ii ^= 1;
    for (int j = 1; j <= m; j++) {
      if (x[i] != y[j]) {
        if (st[ii ^ 1][j] <= 1 && st[ii][j - 1] <= 1) {
          st[ii][j] = 0;
          continue;
        }
        if (st[ii ^ 1][j] > st[ii][j - 1])
          st[ii][j] = st[ii ^ 1][j] - 1;
        else
          st[ii][j] = st[ii][j - 1] - 1;
      } else {
        st[ii][j] = st[ii ^ 1][j - 1] + 2;
        ans = max(ans, st[ii][j]);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
