#include <bits/stdc++.h>
using namespace std;
const int N = 5010 + 10;
const int mod = 1e9 + 7;
char s[N];
char t[N];
int d[N][N];
int main() {
  int n, m;
  cin >> n >> m;
  scanf("%s%s", s + 1, t + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      d[i][j] = max(d[i - 1][j], d[i][j - 1]) - 1;
      if (s[i] == t[j]) {
        d[i][j] = d[i - 1][j - 1] + 2;
        d[i][j] = max(d[i][j], 2);
      }
      ans = max(ans, d[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
