#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const double eps = 0;
const int ms = 0;
const int md = 0;
const long long mod = 998244353;
int n, m;
string a, b;
vector<vector<int> > dp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  dp = vector<vector<int> >(n + 1, vector<int>(m + 1, 0));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 2;
      dp[i][j] = max({dp[i][j], dp[i - 1][j] - 1, dp[i][j - 1] - 1});
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) res = max(res, dp[i][j]);
  cout << res;
}
