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