#include <bits/stdc++.h>
using namespace std;
char s1[5010], s2[5010];
int dp[5010][5010];
int main() {
  int i, j, ind, n, m, ans;
  cin >> n >> m;
  cin >> s1;
  cin >> s2;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      if (s1[i - 1] == s2[j - 1]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
        dp[i][j] = max(dp[i][j], 2);
      }
    }
  }
  ans = 0;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= m; j++) ans = max(ans, dp[i][j]);
  }
  cout << ans;
}
