#include <bits/stdc++.h>
using namespace std;
int dp[5004][5004];
char a[5008], b[5008];
int ans = 0;
int main() {
  int la, lb;
  cin >> la >> lb;
  cin >> a >> b;
  for (int i = 1; i <= la; i++) {
    for (int j = 1; j <= lb; j++) {
      if (a[i - 1] == b[j - 1])
        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 << endl;
}
