#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
  preprocess() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} ____;
int main() {
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  vv<int> dp(n + 1, vector<int>(m + 1));
  int ans = 0;
  for (int i = 0; i < (int)(n); i++)
    for (int j = 0; j < (int)(m); j++) {
      chmax(dp[i][j + 1], dp[i][j] - 1);
      chmax(dp[i + 1][j], dp[i][j] - 1);
      if (a[i] == b[j]) chmax(dp[i + 1][j + 1], dp[i][j] + 2);
    }
  for (int i = 0; i < (int)(n + 1); i++)
    for (int j = 0; j < (int)(m + 1); j++) {
      chmax(ans, dp[i][j]);
    }
  cout << ans << '\n';
}
