#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = (int)2e5 + 100;
const int M = (int)2e6 + 100;
const int inf = (int)1e9 + 2;
int n, m;
string a, b;
bool was[5000][5000];
int table[5000][5000];
int f(int x, int y) {
  if (x == n || y == m) return 0;
  if (was[x][y]) return table[x][y];
  was[x][y] = 1;
  int o = 0;
  o = max(o, f(x + 1, y) - 1);
  o = max(o, f(x, y + 1) - 1);
  if (a[x] == b[y]) o = max(o, f(x + 1, y + 1) + 2);
  return table[x][y] = o;
}
int main() {
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  srand(time(0));
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  int i, j;
  int ans = 0;
  for ((i) = 0; (i) < (n); (i)++) {
    for ((j) = 0; (j) < (m); (j)++) {
      ans = max(ans, f(i, j));
    }
  }
  cout << ans;
}
