#include <bits/stdc++.h>
using namespace std;
long long t, n, m, f[5005][5005];
string a, b;
void solve() {
  long long res = 0;
  a = ' ' + a;
  b = ' ' + b;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i] == b[j])
        f[i][j] = f[i - 1][j - 1] + 2;
      else
        f[i][j] = max((long long)0, max(f[i - 1][j], f[i][j - 1]) - 1);
      res = max(res, f[i][j]);
    }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> a >> b;
  solve();
  return 0;
}
