#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
void solve() {
  ll n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  ll t[n + 1][m + 1];
  memset(t, 0, sizeof(t));
  ll ans = INT_MIN;
  for (ll i = 1; i < n + 1; i++) {
    for (ll j = 1; j < m + 1; j++) {
      if (a[i - 1] == b[j - 1])
        t[i][j] = max(t[i][j], t[i - 1][j - 1] + 2);
      else
        t[i][j] = max(t[i][j], max(t[i - 1][j] - 1, t[i][j - 1] - 1));
      ans = max(ans, t[i][j]);
    }
  }
  cout << ans << endl;
}
int main() {
  ios ::sync_with_stdio(0);
  cin.tie(NULL);
  int tc = 1;
  while (tc--) {
    solve();
  }
  return 0;
}
