#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char ch) {
  ch = tolower(ch);
  return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
inline bool isprime(int n) {
  if (n < 2 || (n % 2 == 0 && n != 2)) return false;
  for (int i = 3; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
class Union {
 private:
  vector<int> saizu, link;

 public:
  Union(int n) {
    saizu.assign(n, 1);
    link.resize(n);
    iota(link.begin(), link.end(), 0);
  }
  int find(int n) {
    if (link[n] == n) return n;
    return link[n] = find(link[n]);
  }
  int same(int a, int b) { return find(a) == find(b); }
  void unite(int a, int b) {
    if (same(a, b)) return;
    a = find(a);
    b = find(b);
    if (saizu[a] < saizu[b]) swap(a, b);
    saizu[a] += saizu[b];
    link[b] = a;
  }
  int getsize(int a) { return saizu[find(a)]; }
};
const int mod = 1e9 + 7;
long long mode(long long a) {
  a %= mod;
  if (a < 0) a += mod;
  return a;
}
long long subt(long long a, long long b) { return mode(mode(a) - mode(b)); }
long long add(long long a, long long b) { return mode(mode(a) + mode(b)); }
long long mult(long long a, long long b) { return mode(mode(a) * mode(b)); }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = mult(res, a);
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
const int N = 5007;
int dp[N][N], n, m;
string a, b;
int ans;
void lcs() {
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
      if (a[i] == b[j]) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
        dp[i][j] = max(dp[i][j], 2);
      }
      ans = max(ans, dp[i][j]);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> a >> b;
  a = '.' + a;
  b = ',' + b;
  lcs();
  cout << ans;
  return 0;
}
