#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m, f[N][N], ans;
char s1[N], s2[N];
signed main() {
  scanf("%d%d%s%s", &n, &m, s1 + 1, s2 + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int &x = f[i][j];
      if (s1[i] == s2[j])
        x = max(x, f[i - 1][j - 1] + 2);
      else
        x = max(x, f[i - 1][j] - 1), x = max(x, f[i][j - 1] - 1),
        x = max(x, f[i - 1][j - 1] - 2);
      ans = max(ans, x);
    }
  printf("%d", ans);
  return 0;
}
