#include <bits/stdc++.h>
using namespace std;
int n, m, dp[5005][5005] = {0}, ans = 0;
string a, b;
int main() {
  scanf("%d%d", &n, &m);
  cin >> a >> b;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      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], dp[i][j + 1] - 1);
      dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j] - 1);
      ans = max(ans, dp[i + 1][j + 1]);
    }
  cout << ans << "\n";
}
