#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
int n, m;
string s1, s2;
int dp[N][N];
int main() {
  cin >> n >> m;
  cin >> s1;
  cin >> s2;
  int answ = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 2 * (s1[i] == s2[j]);
        if (i != 0) dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
        if (j != 0) dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      } else {
        dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
        dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
        int sum = 4 * (s1[i] == s2[j]) - 2;
        dp[i][j] = max(dp[i][j], sum + dp[i - 1][j - 1]);
      }
      answ = max(answ, dp[i][j]);
    }
  }
  cout << answ << endl;
  return 0;
}
