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