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