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