#include <bits/stdc++.h>
using namespace std;
bool iseven(long long n) {
  if (n % 2 == 0)
    return true;
  else {
    return false;
  }
}
long long position(long long a) {
  long long s = 0;
  long double x = a;
  int i = 0;
  while (a > 0) {
    if ((a & 1) == 1) {
      s++;
    }
    a = a >> 1;
    i++;
  }
  return s;
}
long long power(long long x, unsigned long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res % 1000000007 * x % 1000000007) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
void print(vector<long long> a, long long n) {
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << "\n";
}
bool sec(const pair<long long, long long> &a,
         const pair<long long, long long> &b) {
  if (a.first == b.first)
    return (a.second > b.second);
  else {
    return (a.first > b.first);
  }
}
vector<long long> suffixsum(vector<long long> &a, long long n) {
  vector<long long> pre(n, 0);
  pre[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) {
    pre[i] = pre[i + 1] + a[i];
  }
  return pre;
}
vector<long long> preffixsum(vector<long long> &a, long long n) {
  vector<long long> pre(n, 0);
  pre[0] = a[0];
  for (int i = 1; i < n; i++) {
    pre[i] = pre[i - 1] + a[i];
  }
  return pre;
}
map<char, vector<int>> mp;
vector<vector<long long>> dp;
string a, b;
long long fun(int i, int j, int n, int m) {
  if (i >= n || j >= m) return 0ll;
  long long ma = 0, ba = 0;
  if (dp[i][j] == -1) {
    if (a[i] == b[j]) {
      ma = max({fun(i + 1, j + 1, n, m) + 2, fun(i, j + 1, n, m) - 1,
                fun(i + 1, j, n, m) - 1, ma});
    } else {
      ma = max({fun(i, j + 1, n, m) - 1, fun(i + 1, j, n, m) - 1, ma});
    }
    dp[i][j] = ma;
  }
  return dp[i][j];
}
void solve() {
  long long n, m;
  cin >> n >> m;
  cin >> a >> b;
  for (long long i = 0; i < (n); ++i) {
    vector<long long> h;
    for (long long j = 0; j < (m + 1); ++j) {
      h.push_back(-1ll);
    }
    dp.push_back(h);
  }
  fun(0, 0, n, m);
  long long ans = 0;
  for (long long i = 0; i < (n); ++i) {
    for (long long j = 0; j < (m); ++j) {
      if (ans < dp[i][j]) ans = dp[i][j];
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
