#include <bits/stdc++.h>
using namespace std;
const long long N = 5005;
const long long MOD = 998244353;
const long long MAX = 3000000;
const long long INF = 1e18;
long long dp[N][N], n, m;
string s, second;
long long func(long long i, long long j) {
  if (i == -1 or j == -1) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  if (s[i] == second[j]) return dp[i][j] = 2 + max(0ll, func(i - 1, j - 1));
  return dp[i][j] = max({0ll, func(i, j - 1) - 1, func(i - 1, j) - 1});
}
void solve() {
  long long ans = -INF;
  cin >> n >> m >> s >> second;
  for (long long i = 0; i < n + 1; i++)
    for (long long j = 0; j < m + 1; j++) dp[i][j] = -1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ans = max(ans, func(i, j));
    }
  }
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
