#include <bits/stdc++.h>
using namespace std;
int solve(char x[], char y[], int n, int m) {
  int dp[n + 1][m + 1];
  int ans = INT_MIN;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (x[i - 1] == y[j - 1])
        dp[i][j] = max(0, dp[i - 1][j - 1] + 2);
      else
        dp[i][j] = max(0, max(dp[i - 1][j] - 1, dp[i][j - 1] - 1));
      ans = max(ans, dp[i][j]);
    }
  }
  return ans;
}
int main() {
  long long tt, n, m;
  cin >> n >> m;
  char x[n + 1], y[m + 1];
  cin >> x;
  cin >> y;
  cout << solve(x, y, n, m) << endl;
  return 0;
}
