#include <bits/stdc++.h>
using namespace std;
void debug() { cerr << "\n"; }
template <typename H, typename... T>
void debug(H h, T... t) {
  cerr << h;
  if (sizeof...(t)) cerr << ", ";
  debug(t...);
}
const int N = 5005, INF = 1e9 + 5, mod = 1e9 + 7;
int dp[N][N];
int main() {
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  s = '#' + s;
  t = '#' + t;
  for (int i = 1; i <= n; i++) dp[i][0] = -i;
  for (int i = 1; i <= m; i++) dp[0][i] = -i;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = max(dp[i - 1][j - 1], 0) + 2;
      } else {
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}
