#include <bits/stdc++.h>
using namespace std;
const long long N = 5005;
const long long MOD = 998244353;
const long long MAX = 3000000;
const long long INF = 1e18;
long long dp[N][N];
void solve() {
  long long n, m;
  string s, second;
  cin >> n >> m >> s >> second;
  s = '@' + s;
  second = '@' + second;
  long long ans = -INF;
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 1; j < m + 1; j++) {
      if (s[i] == second[j]) {
        dp[i][j] = max(2ll, dp[i - 1][j - 1] + 2);
      }
      dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
      dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
}
