#include <bits/stdc++.h>
using namespace std;
int dp[5001][5001];
int main() {
  int n, m, i, j;
  char a[5000], b[5000];
  cin >> n >> m;
  for (i = 0; i <= n; i++) dp[i][0] = 0;
  for (i = 0; i <= m; i++) dp[0][i] = 0;
  getchar();
  for (i = 0; i < n; i++) a[i] = getchar();
  getchar();
  int ml = 0, mi, mj;
  for (i = 0; i < m; i++) b[i] = getchar();
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      dp[i + 1][j + 1] = 0;
      if (a[i] == b[j]) {
        dp[i + 1][j + 1] = dp[i][j] + 2;
      }
      dp[i + 1][j + 1] =
          max(dp[i + 1][j + 1], max(dp[i][j + 1], dp[i + 1][j]) - 1);
      if (ml < dp[i + 1][j + 1]) {
        ml = dp[i + 1][j + 1];
      }
    }
  }
  cout << ml << endl;
  return 0;
}
