#include <bits/stdc++.h>
using namespace std;
int dp[5003][5003];
string a, b;
int fl = 0;
int solve(int i, int j, int n, int m) {
  if (i == n || j == m) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  int sum = 0, x = 0, y = 0, z = 0;
  if (a[i] == b[j]) {
    sum = max(sum, 2 + solve(i + 1, j + 1, n, m));
  } else {
    sum = max(sum, -1 + solve(i + 1, j, n, m));
    sum = max(sum, -1 + solve(i, j + 1, n, m));
  }
  dp[i][j] = sum;
  return dp[i][j];
}
int main() {
  int i, j, n, m;
  cin >> n >> m;
  cin >> a >> b;
  int res = 0;
  memset(dp, -1, sizeof(dp));
  for (i = n - 1; i >= 0; i--) {
    for (j = m - 1; j >= 0; j--) {
      res = max(res, solve(i, j, n, m));
    }
  }
  cout << res << endl;
  return 0;
}
