#include <bits/stdc++.h>
using namespace std;
long long int len1, len2;
string str1, str2;
vector<vector<long long int>> dp;
void take_input() {
  char s1[5100], s2[5100];
  scanf("%lld%lld", &len1, &len2);
  scanf("%s%s", s1, s2);
  string st1(s1), st2(s2);
  str1 = st1;
  str2 = st2;
  dp.resize(len1 + 1, vector<long long int>(len2 + 1, 0));
}
long long int calc_ans() {
  long long int ans = 0;
  for (int i = 1; i <= len1; i++) {
    for (int j = 1; j <= len2; j++) {
      if (str1[i - 1] == str2[j - 1]) {
        dp[i][j] = max((long long int)0, dp[i - 1][j - 1] + 2);
      } else {
        dp[i][j] = max((long long int)0, max(dp[i - 1][j], dp[i][j - 1]) - 1);
      }
      ans = max(ans, dp[i][j]);
    }
  }
  return ans;
}
int main() {
  take_input();
  long long int ans = calc_ans();
  printf("%lld\n", ans);
}
