#include <bits/stdc++.h>
using namespace std;
int dp[5005][5005];
int main() {
  int n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1;
  cin >> s2;
  dp[0][0] = 0;
  for (int i = 0; i != (n); ++i)
    for (int j = 0; j != (m); ++j) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] - 1);
      dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] - 1);
      if (s1[i] == s2[j])
        dp[i + 1][j + 1] = max(dp[i][j] + 2, dp[i + 1][j + 1]);
    }
  int ma = 0;
  for (int i = 0; i != (n + 1); ++i)
    for (int j = 0; j != (m + 1); ++j) ma = max(ma, dp[i][j]);
  cout << ma << endl;
}
