#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
int dp[maxn][maxn];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(), cout.tie();
  int n, m;
  cin >> n >> m;
  string A, B;
  cin >> A >> B;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max({int(0), dp[i - 1][j] - 1, dp[i][j - 1] - 1});
      if (A[i - 1] == B[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      ans = max(ans, dp[i][j]);
    }
  }
  return cout << ans << endl, 0;
}
