#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7, mxn = 2e5 + 5;
string s1, s2;
int n, m;
short int dp[5001][5001][2];
int help(int id1, int id2, int fl) {
  if (id1 == n || id2 == m) return 0;
  int op1 = -1e9;
  if (fl == 2) return 0;
  if (dp[id1][id2][fl] != -1) return dp[id1][id2][fl];
  if (s1[id1] == s2[id2]) {
    op1 = help(id1 + 1, id2 + 1, 1) + 2;
  }
  int ex = 0;
  if (fl) {
    ex = 1;
  }
  int op2 = help(id1 + 1, id2, fl) - ex;
  int op3 = help(id1, id2 + 1, fl) - ex;
  int op4 = help(id1 + 1, id2, 2);
  int op5 = help(id1, id2 + 1, 2);
  dp[id1][id2][fl] = max({op1, op2, op3, op4, op5});
  return dp[id1][id2][fl];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> s1 >> s2;
  memset(dp, -1, sizeof(dp));
  cout << help(0, 0, 0);
  return 0;
}
