#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) {
  if (x >= y)
    return x;
  else
    return y;
}
int main() {
  long long n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1;
  cin >> s2;
  long long ans = INT_MIN;
  long long dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s1[i - 1] == s2[j - 1])
        dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
      else
        dp[i][j] = max(dp[i][j], max(dp[i][j - 1] - 1, dp[i - 1][j] - 1));
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
