#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
const int MAX = 1020000;
long long dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
long long dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const double pi = acos(-1);
const double eps = 1e-7;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
template <typename T>
inline void print(T &a) {
  for (long long i = 0; i < (a.size()); i++) cout << a[i] << " ";
  cout << "\n";
}
template <typename T1, typename T2>
inline void print2(T1 a, T2 b) {
  cout << a << " " << b << "\n";
}
template <typename T1, typename T2, typename T3>
inline void print3(T1 a, T2 b, T3 c) {
  cout << a << " " << b << " " << c << "\n";
}
long long pcount(long long x) { return __builtin_popcountll(x); }
const int mod = 998244353;
void solve() {
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (m); j++) {
      chmax(dp[i + 1][j + 1], max(dp[i][j + 1] - 1, dp[i + 1][j] - 1));
      if (s[i] == t[j]) {
        chmax(dp[i + 1][j + 1], dp[i][j] + 2);
      } else {
        chmax(dp[i + 1][j + 1], dp[i][j] - 2);
      }
    }
  }
  int ans = 0;
  for (long long i = 0; i < (n + 1); i++)
    for (long long j = 0; j < (m + 1); j++) chmax(ans, dp[i][j]);
  cout << ans << "\n";
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
}
