#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897;
int m, n, dp[5005][5005], ans;
char yy[5005], sy[5005];
signed main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  cin >> m >> n >> yy >> sy;
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j) {
      if (yy[i] == sy[j])
        dp[i + 1][j + 1] = dp[i][j] + 2;
      else
        dp[i + 1][j + 1] = max(max(dp[i + 1][j], dp[i][j + 1]) - 1, 0);
      ans = max(ans, dp[i + 1][j + 1]);
    }
  cout << ans;
  return 0;
}
