#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b) {
  return (a % 1000000007 + b % 1000000007) % 1000000007;
}
long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
int n, m, dp[5005][5005];
string s, t;
void solve() {
  int ans = 0;
  for (long long i = 0; i < (n + 1); ++i) {
    for (long long j = 0; j < (m + 1); ++j) {
      if (i == 0 || j == 0)
        dp[i][j] = 0;
      else if (s[i - 1] == t[j - 1])
        dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
      else
        dp[i][j] = max(dp[i][j], max(dp[i - 1][j] - 1, dp[i][j - 1] - 1));
      ans = max(dp[i][j], ans);
    }
  }
  cout << ans;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) {
    cin >> n >> m;
    cin >> s >> t;
    solve();
    cout << "\n";
  }
  return 0;
}
