#include <bits/stdc++.h>
using namespace std;
long long n, m;
string a, b;
vector<vector<long long>> dp(5005, vector<long long>(5005, -1));
long long fun(long long i, long long j) {
  if (i == n or j == m) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  long long m = 0;
  m = max({m, fun(i + 1, j) - 1, fun(i, j + 1) - 1});
  if (a[i] == b[j]) m = max(m, fun(i + 1, j + 1) + 2);
  return dp[i][j] = m;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  cin >> a >> b;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) ans = max(ans, fun(i, j));
  }
  cout << ans << "\n";
  return 0;
}
