#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\t";
  err(++it, args...);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& c, pair<T1, T2>& v) {
  c << "(" << v.first << "," << v.second << ")";
  return c;
}
template <template <class...> class TT, class... T>
ostream& operator<<(ostream& out, TT<T...>& c) {
  out << "{ ";
  for (auto& x : c) out << x << " ";
  out << "}";
  return out;
}
const int LIM = 5005, MOD = 1e9 + 7;
const long double EPS = 1e-9;
int read() {
  int xx = 0, ff = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    xx = (xx << 3) + (xx << 1) + ch - '0';
    ch = getchar();
  }
  return xx * ff;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
string a, b;
int dp[LIM][LIM];
int solve(int p1, int p2) {
  int s1 = a.size(), s2 = b.size();
  if (p1 == s1 || p2 == s2) return 0;
  if (dp[p1][p2] != -1) return dp[p1][p2];
  int ans = max(0, solve(p1 + 1, p2) - 1);
  ans = max(ans, solve(p1, p2 + 1) - 1);
  if (a[p1] == b[p2]) {
    ans = 2 + max(solve(p1 + 1, p2 + 1), 0);
  }
  return (dp[p1][p2] = ans);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  for (int i = 0; i < LIM; ++i) {
    for (int j = 0; j < LIM; ++j) {
      dp[i][j] = -1;
    }
  }
  int fans = 0;
  for (int i = 0; i < a.length(); ++i) {
    for (int j = 0; j < b.length(); ++j) {
      if (dp[i][j] == -1) solve(i, j);
      fans = max(fans, dp[i][j]);
    }
  }
  cout << fans << '\n';
  return 0;
}
