#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[5001], b[5001];
int dp[5002][5002] = {0};
int ans = 0;
void solve() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = max(dp[i - 1][j - 1] + 2, 0);
      }
      dp[i][j] = max(max(dp[i - 1][j], dp[i][j - 1]) - 1, dp[i][j]);
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  solve();
  return 0;
}
