#include <bits/stdc++.h>
using namespace std;
int dp[5001][5001][2];
string a;
string b;
int go(int idxa, int idxb, int state) {
  if (idxa == a.size() || idxb == b.size()) {
    return 0;
  }
  if (dp[idxa][idxb][state] != -1) {
    return dp[idxa][idxb][state];
  }
  int best = 0;
  if (state == 0) {
    if (a[idxa] == b[idxb]) {
      best = max(best, 2 + go(idxa + 1, idxb + 1, 1));
    }
    best = max(best, go(idxa + 1, idxb, 0));
    best = max(best, go(idxa, idxb + 1, 0));
    best = max(best, go(idxa + 1, idxb + 1, 0));
  } else if (state == 1) {
    if (a[idxa] == b[idxb]) {
      best = max(best, 2 + go(idxa + 1, idxb + 1, 1));
    }
    best = max(best, -1 + go(idxa + 1, idxb, 1));
    best = max(best, -1 + go(idxa, idxb + 1, 1));
    best = max(best, -2 + go(idxa + 1, idxb + 1, 1));
    best = max(best, 0);
  }
  dp[idxa][idxb][state] = best;
  return best;
}
void solve() {
  int n, m;
  cin >> n >> m;
  string A, B;
  cin >> A >> B;
  memset(dp, -1, sizeof(dp));
  a = A;
  b = B;
  cout << go(0, 0, 0) << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
