#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b & 1) return a * power(a, b - 1);
  long long int temp = power(a, b / 2);
  return temp * temp;
}
bool mycompare(long long int a, long long int b) { return a > b; }
int main() {
  int n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  int dp[n + 1][m + 1];
  int ans = 0;
  memset(dp, 0, sizeof dp);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s1[i - 1] == s2[j - 1])
        dp[i][j] = dp[i - 1][j - 1] + 2;
      else {
        dp[i][j] = max(max(dp[i - 1][j] - 1, dp[i][j - 1] - 1), 0);
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}
