#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 1;
char a[N], b[N];
int f[N][N];
int res;
int n, m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  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] = f[i - 1][j - 1] + 2;
      }
      f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]) - 1);
      res = max(res, f[i][j]);
    }
  }
  cout << res;
}
