#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1};
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long ceil1(long long a, long long b) { return (a + b - 1) / b; }
void read(vector<long long>& arr) {
  for (long long i = 0; i < int(arr.size()); i++) cin >> arr[i];
}
void read_graph(vector<vector<long long>>& g, long long m) {
  while (m--) {
    long long x, y;
    cin >> x >> y;
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
}
int calc(vector<vector<int>>& dp, int x, int y) {
  if (x < 0 or y < 0) {
    return 0;
  }
  return dp[x][y];
}
void solve() {
  int n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  vector<vector<int>> dp(
      vector<vector<int>>(n + 3, vector<int>(m + 3, INT_MIN)));
  int ans = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = max(calc(dp, i - 1, j - 1) + 2, dp[i][j]);
        dp[i][j] = max(calc(dp, i - 1, j) - 1, dp[i][j]);
        dp[i][j] = max(calc(dp, i, j - 1) - 1, dp[i][j]);
        dp[i][j] = max(2, dp[i][j]);
      } else {
        dp[i][j] = max(calc(dp, i - 1, j - 1) - 2, dp[i][j]);
        dp[i][j] = max(calc(dp, i - 1, j) - 1, dp[i][j]);
        dp[i][j] = max(calc(dp, i, j - 1) - 1, dp[i][j]);
        dp[i][j] = max(dp[i][j], -2);
      }
      ans = max(ans, dp[i][j]);
    }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
