#include <bits/stdc++.h>
const long long mod = 1000 * 1000 * 1000 + 7;
const long long mod1 = 998244353;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (long long)(res * x);
    y = y >> 1;
    x = (long long)(x * x);
  }
  return res;
}
long long dp[5005][5005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  for (int i = 0; i < n + 1; i++) dp[i][0] = -i;
  for (int i = 0; i < m + 1; i++) dp[0][i] = -i;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = max(2LL, dp[i - 1][j - 1] + 2LL);
      } else {
        dp[i][j] = max(0LL, max(dp[i - 1][j], dp[i][j - 1]) - 1);
      }
    }
  }
  long long maxn = -INF;
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      maxn = max(dp[i][j], maxn);
    }
  }
  cout << maxn;
  return 0;
}
