#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int dp[N][N];
char a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  cin >> (a + 1) >> (b + 1);
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j])
        dp[i][j] = dp[i - 1][j - 1] + 2;
      else
        dp[i][j] = max({dp[i - 1][j] - 1, dp[i][j - 1] - 1, 0});
      mx = max(mx, dp[i][j]);
    }
  }
  cout << mx;
  return 0;
}
