#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 5;
char a[maxn], b[maxn];
int dp[maxn][maxn];
int main() {
  int n, m;
  cin >> n >> m;
  scanf("%s%s", a + 1, b + 1);
  int max_ = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      dp[i][j] = max(dp[i][j], dp[i][j - 1] - 1);
      dp[i][j] = max(dp[i][j], dp[i - 1][j] - 1);
      max_ = max(max_, dp[i][j]);
    }
  }
  cout << max_ << endl;
  return 0;
}
