#include <bits/stdc++.h>
using namespace std;
string a, b;
int dp[5003][5003];
int find(int s, int t, int n, int m) {
  int i = s;
  int j = t;
  if (s == n || t == m) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  if (a[s] == b[t]) {
    dp[i][j] = 2 + find(s + 1, t + 1, n, m);
  }
  dp[i][j] = max(max(0, dp[i][j]),
                 max(-1 + find(s + 1, t, n, m), -1 + find(s, t + 1, n, m)));
  return dp[s][t];
}
int main() {
  int n, m;
  cin >> n >> m;
  cin >> a >> b;
  memset(dp, -1, sizeof(dp));
  find(0, 0, n, m);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
  return 0;
}
