#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
int n, m, dp[N][N];
string a, b;
vector<int> nxt[N];
int f(int i, int j) {
  if (i >= n || j >= m) return 0;
  if (~dp[i][j]) return dp[i][j];
  int r = 0;
  r = max(r, -1 + f(i + 1, j));
  int k = a[i] - 'a';
  if (nxt[j][k] < m) {
    r = max(r, 4 + (-1) - (nxt[j][k] - j + 1) + f(i + 1, nxt[j][k] + 1));
  }
  return dp[i][j] = r;
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> a >> b;
  vector<int> t(26, m + 1);
  for (int i = m - 1; i >= 1; i--) {
    t[b[i] - 'a'] = i;
    nxt[i] = t;
  }
  memset(dp, -1, sizeof dp);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      if (a[i] == b[j]) {
        ans = max(ans, 2 + f(i + 1, j + 1));
      }
  }
  cout << ans << endl;
}
