#include <bits/stdc++.h>
using namespace std;
void IO() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long binary_exponention(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binary_exponention(a, b / 2);
  if (b % 2) return (res * res % 1000000007) * a % 1000000007;
  return res * res % 1000000007;
}
inline void read(int a[], int n, int which = 0) {
  if (which)
    for (int i = 1; i <= n; i++) cin >> a[i];
  else
    for (int i = 0; i < n; i++) cin >> a[i];
}
inline void write(int a[], int n, int which = 0) {
  if (which == 0)
    for (int i = 0; i < n; i++) cout << a[i] << " ";
  else
    for (int i = 1; i <= n; i++) cout << a[i] << " ";
}
int dir8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dir4i[4] = {-1, 0, 1, 0};
int dir4j[4] = {0, -1, 0, 1};
void solve() {
  int n, m;
  cin >> n >> m;
  int dp[n + 1][m + 1];
  string a, b;
  cin >> a >> b;
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1])
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
      else
        dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]) - 1);
    }
  int mx = 0;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) mx = max(mx, dp[i][j]);
  cout << mx << "\n";
}
int main() {
  IO();
  solve();
}
