#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  long long dp[n + 1][m + 1];
  memset(dp, 0, sizeof dp);
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], 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;
}
signed main() {
  long long t = 1;
  for (long long i = 1; i <= t; i++) solve();
}
