#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[m + 1][n + 1], ans = 0;
  string x, y;
  cin >> x >> y;
  for (int i = 0; i <= n; i++) {
    a[0][i] = 0;
  }
  for (int i = 0; i <= m; i++) {
    a[i][0] = 0;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (y[i - 1] == x[j - 1]) {
        a[i][j] = 2 + a[i - 1][j - 1];
        ans = max(a[i][j], ans);
      } else {
        a[i][j] = max(0, max(a[i - 1][j] - 1, a[i][j - 1] - 1));
        ans = max(a[i][j], ans);
      }
    }
  }
  cout << ans;
}
