#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long N = 5005;
long long dp[N][N];
long long solve() {
  long long n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  long long ans = 0;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (s1[i - 1] == s2[j - 1]) {
        dp[i][j] = 2 + max(0LL, dp[i - 1][j - 1]);
      }
      maxs(dp[i][j], dp[i - 1][j] - 1);
      maxs(dp[i][j], dp[i][j - 1] - 1);
      maxs(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
