#include <bits/stdc++.h>
namespace Solution {
const int N = 5002;
int s[N][N];
void solve() {
  int n, m;
  std::cin >> n >> m;
  std::string a, b;
  std::cin >> a >> b;
  for (int i = 0; i < n; i++) {
    s[i][0] = 0;
  }
  for (int i = 0; i < m; i++) {
    s[0][i] = 0;
  }
  int res = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) {
        s[i][j] = s[i - 1][j - 1] + 2;
      } else {
        s[i][j] = std::max(0, std::max(s[i - 1][j] - 1, s[i][j - 1] - 1));
      }
      res = std::max(res, s[i][j]);
    }
  }
  std::cout << res << std::endl;
}
}  // namespace Solution
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  Solution::solve();
  return 0;
}
