#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int n, long long int m);
long long int power(long long int a, long long int n, long long int m) {
  if (n == 0) return 1;
  long long int x = power(a, n / 2, m);
  if (n % 2 != 0)
    return (((a * x) % m) * (x) % m) % m;
  else
    return (x * x) % m;
}
string s1, s2;
long long int dp[5001][5001];
long long int fun(long long int i, long long int j, long long int n,
                  long long int m) {
  if (i == n || j == m) return 0;
  if (dp[i][j] != -1) {
    return dp[i][j];
  }
  if (s1[i] == s2[j]) dp[i][j] = 2 + fun(i + 1, j + 1, n, m);
  return dp[i][j] = max({0LL, dp[i][j], fun(i + 1, j, n, m) - 1,
                         -1 + fun(i, j + 1, n, m)});
}
int32_t main() {
  long long int i, n, j, x, y, m, k, t, sum, count, cnt, b, c, d, j1, z, a,
      temp;
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  cin >> s1 >> s2;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      dp[i][j] = -1;
    }
  }
  fun(0, 0, n, m);
  long long int ans = 0;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
  return 0;
}
