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