#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long dp[5005][5005];
string s1, s2;
long long n, m;
long long solve(long long i, long long j) {
  if (i == n || j == m) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  long long ans = 0;
  if (s1[i] == s2[j]) {
    ans = max(ans, 2 + solve(i + 1, j + 1));
  } else {
    long long temp = 0;
    temp = max(temp, solve(i + 1, j));
    temp = max(temp, solve(i, j + 1));
    if (temp > 0) temp -= 1;
    ans = max(ans, temp);
  }
  return dp[i][j] = ans;
}
int32_t main() {
  fast();
  cin >> n >> m;
  cin >> s1 >> s2;
  for (long long i = 0; i < n + 5; i++) {
    for (long long j = 0; j < m + 5; j++) dp[i][j] = -1;
  }
  long long ans = solve(0, 0);
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ans = max(ans, solve(i, j));
    }
  }
  cout << ans << "\n";
  return 0;
}
