#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long x = 0, f = 0;
  char c = getchar();
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return f ? -x : x;
}
inline int max(int a, int b, int c) { return max(a, max(b, c)); }
int n, m;
char s[5010], t[5010];
int f[5010][5010], ans;
int main() {
  scanf("%d%d%s%s", &n, &m, s + 1, t + 1);
  for (int i = n; i; --i)
    for (int j = m; j; --j) {
      if (s[i] == t[j])
        f[i][j] = max(f[i][j], f[i + 1][j + 1] + 2);
      else
        f[i][j] = max(f[i + 1][j] - 1, f[i][j + 1] - 1, 0);
      ans = max(ans, f[i][j]);
    }
  cout << ans << endl;
  return 0;
}
