#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int n, m, dp[N][N], anss;
char s1[N], s2[N];
int main() {
  cin >> n >> m;
  cin >> s1 + 1 >> s2 + 1;
  anss = 0;
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s1[i] == s2[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;
      }
      anss = max(anss, dp[i][j]);
    }
  }
  cout << anss << endl;
  return 0;
}
