#include <bits/stdc++.h>
using namespace std;
const int M = 5e3 + 5, C = 1e5 + 5;
int n, m, dp[M][M];
string a, b;
int solve(int ind1, int ind2) {
  if (ind1 == n || ind2 == m) return 0;
  if (~dp[ind1][ind2]) return dp[ind1][ind2];
  int ans = 0;
  if (a[ind1] == b[ind2]) {
    ans = solve(ind1 + 1, ind2 + 1) + 2;
  }
  ans = max({ans, solve(ind1 + 1, ind2) - 1, solve(ind1, ind2 + 1) - 1});
  return dp[ind1][ind2] = ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  memset(dp, -1, sizeof(dp));
  cin >> n >> m >> a >> b;
  int anss = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      anss = max(anss, solve(i, j));
    }
  }
  cout << anss;
  return 0;
}
