#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  int val[n + 3][m + 3], dp[n + 3][m + 3];
  for (int i = 0; i <= n; i++) {
    val[i][0] = 0;
    dp[i][0] = 0;
  }
  for (int i = 0; i <= m; i++) {
    val[0][i] = 0;
    dp[0][i] = 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        val[i + 1][j + 1] = 2;
      } else {
        val[i + 1][j + 1] = -1;
      }
    }
  }
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(0, val[i][j]);
      if (val[i][j] == 2) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + val[i][j]);
      } else {
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + val[i][j]);
        dp[i][j] = max(dp[i][j], dp[i][j - 1] + val[i][j]);
      }
      mx = max(mx, dp[i][j]);
    }
  }
  cout << mx;
  return 0;
}
