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