#include <bits/stdc++.h>
using namespace std;
const int INF = -123456;
int n, m;
string a, b;
int dp[5005][5005];
int solve(int x, int y) {
  int &ret = dp[x][y];
  if (ret != INF) return ret;
  ret = 0;
  if (x != n) ret = max(ret, solve(x + 1, y) - 1);
  if (y != m) ret = max(ret, solve(x, y + 1) - 1);
  if (x != n && y != m && a[x] == b[y]) ret = max(ret, solve(x + 1, y + 1) + 2);
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> a >> b;
  fill(&dp[0][0], &dp[5005][0], INF);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      ans = max(ans, solve(i, j));
    }
  }
  cout << ans;
}
