#include <bits/stdc++.h>
using namespace std;
ifstream in("in.in");
ofstream out("out.out");
int dp[5005][5005], n, m;
bool v[5005][5005];
char x[5005], y[5005];
int solve(int n, int m) {
  if (v[n][m] == 1) return dp[n][m];
  v[n][m] = 1;
  dp[n][m] = max(dp[n][m], 0);
  dp[n][m] = max(dp[n][m], solve(n - 1, m) - 1);
  dp[n][m] = max(dp[n][m], solve(n, m - 1) - 1);
  if (x[n] == y[m]) dp[n][m] = max(dp[n][m], solve(n - 1, m - 1) - 2 + 4);
  return dp[n][m];
}
int main() {
  int i, j;
  cin >> n >> m;
  cin >> x + 1 >> y + 1;
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n; j++) {
      dp[i][j] = -1000000005;
      v[i][j] = 0;
    }
  dp[0][0] = 0;
  v[0][0] = 1;
  for (i = 1; i <= n; i++) {
    dp[i][0] = 0;
    v[i][0] = 1;
  }
  for (i = 1; i <= m; i++) {
    dp[0][i] = 0;
    v[0][i] = 1;
  }
  solve(n, m);
  int sol = 0;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      sol = max(sol, dp[i][j]);
    }
  }
  cout << sol << "\n";
}
