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