#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  long long** dp = new long long*[n + 1];
  for (long long i = 0; i <= n; i++) {
    dp[i] = new long long[m + 1];
    for (long long j = 0; j <= m; j++) {
      dp[i][j] = 0;
    }
  }
  vector<long long> sAns;
  vector<long long> tAns;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = (dp[i - 1][j - 1] + 2);
      } else {
        long long u = 0;
        dp[i][j] = max(u, max(dp[i - 1][j] - 1, dp[i][j - 1] - 1));
      }
    }
  }
  long long maxi = 0;
  for (long long i = 0; i <= n; i++) {
    for (long long j = 0; j <= m; j++) {
      maxi = max(maxi, dp[i][j]);
    }
  }
  cout << maxi << endl;
}
