#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[5001], t[5001];
int dp[5001][5001];
int main() {
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> t[i];
    }
    for (int i = 0; i < m + 1; i++) {
      dp[0][i] = 0;
    }
    for (int j = 0; j < n + 1; j++) {
      dp[j][0] = 0;
    }
    int maxi = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (s[i] == t[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 2;
        } else {
          dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]) - 1;
          dp[i + 1][j + 1] = max(0, dp[i + 1][j + 1]);
        }
        maxi = max(dp[i + 1][j + 1], maxi);
      }
    }
    cout << maxi << "\n";
  }
}
