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