#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast,no-stack-protector")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
function<void(void)> ____ = []() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
};
template <typename T>
vector<T> &operator<<(vector<T> &__container, T x) {
  __container.push_back(x);
  return __container;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &__container) {
  for (T _ : __container) out << _ << ' ';
  return out;
}
void sci() {}
template <typename... Args>
void sci(int &x, Args &...args) {
  scanf("%d", &x);
  sci(args...);
}
void scl() {}
template <typename... Args>
void scl(long long int &x, Args &...args) {
  scanf("%lld", &x);
  scl(args...);
}
const int MAXN = 5e3 + 7;
int n, m, f[MAXN][MAXN];
char s[MAXN], t[MAXN];
void solve() {
  sci(n, m);
  scanf("%s", s + 1);
  scanf("%s", t + 1);
  int ret = 0;
  for (int i = n; i >= 1; i--)
    for (int j = m; j >= 1; j--) {
      f[i][j] = max({0, f[i + 1][j] - 1, f[i][j + 1] - 1,
                     f[i + 1][j + 1] - 2 + (s[i] == t[j] ? 4 : 0)});
      ret = max(ret, f[i][j]);
    }
  cout << ret << "\n";
}
int main() {
  solve();
  return 0;
}
