#include <bits/stdc++.h>
using namespace std;
int n, m;
int dp[5012][5012];
int main() {
  cin >> n >> m;
  string str1, str2;
  cin >> str1 >> str2;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (str1[i - 1] == str2[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 2;
      } else {
        dp[i][j] = max(dp[i - 1][j] - 1, dp[i][j - 1] - 1);
        dp[i][j] = max(dp[i][j], 0);
      }
    }
  }
  int maximum = 0;
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= m; ++j) {
      maximum = max(maximum, dp[i][j]);
    }
  }
  cout << maximum;
}
