#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
const int logN = 17;
int n, m, dp[N][N], mx[N][N];
char s1[N], s2[N];
int main() {
  scanf("%d %d %s %s", &n, &m, s1 + 1, s2 + 1);
  int ans = 0;
  for (int i = 1; i <= n + 1; i++)
    for (int j = 1; j <= m + 1; j++) mx[i][j] = -inf;
  for (int i = n; i >= 1; i--) {
    for (int j = m; j >= 1; j--) {
      if (s1[i] != s2[j]) {
        dp[i][j] = 0;
      } else {
        dp[i][j] = max(2, mx[i + 1][j + 1] + 4 + i + j);
      }
      ans = max(ans, dp[i][j]);
      mx[i][j] = max(mx[i + 1][j], mx[i][j + 1]);
      mx[i][j] = max(mx[i][j], dp[i][j] - i - j);
    }
  }
  cout << ans << endl;
  return 0;
}
