#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[5010], b[5010];
int f[5010][5010];
int ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (a[i] == b[j])
        f[i][j] = max(f[i - 1][j - 1] + 2, 2);
      else
        f[i][j] = max(f[i][j - 1] - 1, f[i - 1][j] - 1);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m; ++j) ans = max(ans, f[i][j]);
  cout << ans;
  return 0;
}
