#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define pb push_back
#define mp make_pair
template <typename T> void chkmin(T &x,T y){y<x?x=y:T();}
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void readint(T &x)
{
	int f=1;char c;x=0;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=1000000007;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
inline int inv(int x){return qmi(x,MOD-2);}
const int MAXN=5005;

int n,m;
char a[MAXN],b[MAXN];
int f[MAXN][MAXN];

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(n),readint(m);
	scanf("%s%s",a+1,b+1);
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			f[i][j]=max(f[i][j-1]-1,f[i-1][j]-1);
			if(a[i]==b[j])chkmax(f[i][j],max(f[i-1][j-1]+2,1));
			chkmax(ans,f[i][j]);
		}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define pb push_back
#define mp make_pair
template <typename T> void chkmin(T &x,T y){y<x?x=y:T();}
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void readint(T &x)
{
	int f=1;char c;x=0;
	for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	x*=f;
}
const int MOD=1000000007;
inline int dmy(int x){return x>=MOD?x-MOD:x;}
inline void inc(int &x,int y){x=dmy(x+y);}
int qmi(int x,int y)
{
	int ans=1;
	for(;y;y>>=1,x=1ll*x*x%MOD)
		if(y&1)ans=1ll*ans*x%MOD;
	return ans;
}
inline int inv(int x){return qmi(x,MOD-2);}
const int MAXN=5005;

int n,m;
char a[MAXN],b[MAXN];
int f[MAXN][MAXN];

int main()
{
	#ifdef LOCAL
	freopen("code.in","r",stdin);
//	freopen("code.out","w",stdout);
	#endif
	readint(n),readint(m);
	scanf("%s%s",a+1,b+1);
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			f[i][j]=max(0,max(f[i][j-1]-1,f[i-1][j]-1));
			if(a[i]==b[j])chkmax(f[i][j],max(f[i-1][j-1]+2,1));
			chkmax(ans,f[i][j]);
		}
	printf("%d\n",ans);
	return 0;
}


// ./b-catching-cheaters.yml
#include "bits/stdc++.h"
using namespace std;

// Defines
#define fs first
#define sn second
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
// Basic type definitions
using ll = long long; using ull = unsigned long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<long long, long long>;
// PBDS order statistic tree
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T, class comp = less<T>> using os_tree = tree<T, null_type, comp, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V, class comp = less<K>> using treemap = tree<K, V, comp, rb_tree_tag, tree_order_statistics_node_update>;
// HashSet
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash { ll operator()(ll x) const { return x ^ RANDOM; } };
template <typename T, class Hash> using hashset = gp_hash_table<T, null_type, Hash>;
template <typename K, typename V, class Hash> using hashmap = gp_hash_table<K, V, Hash>;
// More utilities
int SZ(string &v) { return v.length(); }
template <typename C> int SZ(C &v) { return v.size(); }
template <typename C> void UNIQUE(vector<C> &v) { sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); }
template <typename T, typename U> void maxa(T &a, U b) { a = max(a, b); }
template <typename T, typename U> void mina(T &a, U b) { a = min(a, b); }
const ll INF = 0x3f3f3f3f, LLINF = 0x3f3f3f3f3f3f3f3f;

const int MN = 5001;
int N, M;
pair<short, short> dp[MN][MN]; // len, start ind
string S, T;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> (N) >> (M) >> (S) >> (T);

    int ans = 0;
    for (auto i = 1; i <= N; i++) {
        for (auto j = 1; j <= M; j++) {
            dp[i][j] = max({dp[i][j], {dp[i - 1][j].fs, dp[i - 1][j].sn - (dp[i - 1][j].fs > 0)},
                    {dp[i][j - 1].fs, dp[i][j - 1].sn - (dp[i][j - 1].fs > 0)}});

            if (S[i - 1] == T[j - 1]) {
                dp[i][j] = max(dp[i][j], {dp[i - 1][j - 1].fs + 1, dp[i - 1][j - 1].sn - 2});
                maxa(ans, 4 * (int)dp[i][j].fs + (int)dp[i][j].sn);
            }

            // cout<<"i="<<(i)<<", "; cout<<"j="<<(j)<<", "; cout<<"dp[i][j].fs="<<(dp[i][j].fs)<<", "; cout<<"dp[i][j].sn="<<(dp[i][j].sn)<<", "; cout << endl; // db i,j,dp[i][j].fs,dp[i][j].sn
        }
    }

    cout << (ans) << '\n';

    return 0;
}


// ./b-catching-cheaters.yml
#include "bits/stdc++.h"
using namespace std;

// Defines
#define fs first
#define sn second
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
// Basic type definitions
using ll = long long; using ull = unsigned long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<long long, long long>;
// PBDS order statistic tree
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T, class comp = less<T>> using os_tree = tree<T, null_type, comp, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V, class comp = less<K>> using treemap = tree<K, V, comp, rb_tree_tag, tree_order_statistics_node_update>;
// HashSet
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash { ll operator()(ll x) const { return x ^ RANDOM; } };
template <typename T, class Hash> using hashset = gp_hash_table<T, null_type, Hash>;
template <typename K, typename V, class Hash> using hashmap = gp_hash_table<K, V, Hash>;
// More utilities
int SZ(string &v) { return v.length(); }
template <typename C> int SZ(C &v) { return v.size(); }
template <typename C> void UNIQUE(vector<C> &v) { sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); }
template <typename T, typename U> void maxa(T &a, U b) { a = max(a, b); }
template <typename T, typename U> void mina(T &a, U b) { a = min(a, b); }
const ll INF = 0x3f3f3f3f, LLINF = 0x3f3f3f3f3f3f3f3f;

const int MN = 5001;
int N, M,
    dp[MN][MN];
string S, T;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> (N) >> (M) >> (S) >> (T);

    int ans = 0;
    for (auto i = 1; i <= N; i++) {
        for (auto j = 1; j <= M; j++) {
            dp[i][j] = max({dp[i][j], dp[i - 1][j] - 1, dp[i][j - 1] - 1});
            if (S[i - 1] == T[j - 1]) {
                maxa(dp[i][j], dp[i - 1][j - 1] + 2);
                maxa(ans, dp[i][j]);
            }

            // cout<<"i="<<(i)<<", "; cout<<"j="<<(j)<<", "; cout<<"dp[i][j]="<<(dp[i][j])<<", "; cout << endl; // db i,j,dp[i][j]
        }
    }

    cout << (ans) << '\n';

    return 0;
}


#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <numeric>
#include <vector>
#include <string>
#include <cmath>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FORR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR(i, a) FORR(i, 1, a)
#define FORRI(a, b) FORR(i, a, b)
#define FORI(a) FOR(i, a)
#define FORIN FORI(N)

#define RROF(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ROF(i, a) RROF(i, a, 1)
#define RROFI(a, b) RROF(i, a, b)
#define ROFI(a) ROF(i, a)
#define ROFIN ROFI(N)

#define FORT(it, l) for (auto it = (l).begin(); it != (l).end();)
#define FORIT(l) FORT(it, l)

#define FORA(e, l) for (auto e : l)
#define FORE(l) FORA(e, l)

#define SIN cin
#define RN SIN >> N
#define RNM RN >> M
#define RARR(A, N) FORI(N) SIN >> A[i]
#define RARR2(A, N) RARR(A, N)[0] >> A[i][1]
#define RARR3(A, N) RARR2(A, N) >> A[i][2]
#define RARR0(A, N) FORRI(0, N - 1) SIN >> A[i]
#define RA RARR(A, N)
#define RA2 RARR2(A, N)
#define RA3 RARR3(A, N)
#define RA0 RARR0(A, N)
#define RNA RN; RA
#define RNA2 RN; RA2
#define RNA3 RN; RA3
#define RDADJ FORI(M) SIN >> u >> v, adj[u].insert(v)
#define RUADJ RDADJ, adj[v].insert(u)

#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x) memset(x, ~(char)0, sizeof(x))
#define SRT(l) sort(l.begin(), l.end())
#define SRTC(l, c) sort(l.begin(), l.end(), c)
#define SRTN(l) sort(l + 1, l + N + 1)
#define SRTNC(l, c) sort(l + 1, l + N + 1, c)
#define REV(l) reverse(l.begin(), l.end())
#define REVN(l) reverse(l + 1, l + N + 1)

#define SUM(l) accumulate(l.begin(), l.end(), 0)
#define SUMA(a, n) accumulate(a, a + n, 0)
#define SUMN(a) SUMA(a + 1, N)

#define MOD(x) (MOD_VAL + (x) % MOD_VAL) % MOD_VAL
#define MULT(x, y) MOD((lli)(x) * (lli)(y))
#define ADD(x, y) MOD((lli)(x) + (lli)(y))
#define INV(x) exp((x), MOD_VAL - 2)
#define MMULT(x, y) x = MULT(x, y)
#define MADD(x, y) x = ADD(x, y)
#define MOD_VAL 1000000007LL

#define MGET(m, k) [&](){ auto it = (m).find(k); return it == (m).end() ? 0 : it->se; }()
#define MINC(m, k, v) [&](){ auto it = (m).find(k); if (it == (m).end()) (m).insert({ (k), (v) }); else it->se += (v); }()

#define fi first
#define se second

#define CHNL out[out.length() - 1] = '\n'
#define OUTN(x) out += TOS(x), APNL
#define OUTS(x) out += TOS(x) + " "
#define OUTA(l) FORA(e, l) OUTS(e); CHNL
#define OUTF(a, n) FOR(i, n) OUTS((a)[i]); CHNL
#define APNL out += "\n"
#define TOS(x) to_string(x)

#define FAIL { out += "-1\n"; return; }

#define MAX_N 5001
#define NBT 32

typedef long double ld;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef set<int, bool(*)(int, int)> sic;
typedef set<pii, bool(*)(pii, pii)> spic;
typedef set<lli, bool(*)(lli, lli)> slc;
typedef set<pll, bool(*)(pll, pll)> splc;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<lli, lli> mll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef list<pii> lpi;
typedef list<pll> lpl;
typedef list<int> li;
typedef list<lli> ll;
typedef set<pii> spi;
typedef set<pll> spl;
typedef set<int> si;
typedef set<lli> sl;
typedef string str;

pii operator+(const pii& x, const pii& y) { return { x.fi + y.fi, x.se + y.se }; }
pll operator+(const pll& x, const pll& y) { return { x.fi + y.fi, x.se + y.se }; }

lli gcd(lli a, lli b) { return a >= b ? b ? gcd(b, a % b) : a : gcd(b, a); }
lli lcm(lli a, lli b) { return a / gcd(a, b) * b; }

lli exp(lli a, lli b)
{
	lli r = 1;
	while (b)
		MMULT(r, b & 1 ? a : 1), MMULT(a, a), b >>= 1;
	return r;
}

str out;
lli T;

#define GDP(i, j) (i < 0 || j < 0 ? 0 : DP[i][j])
si adj[MAX_N];
int DP[MAX_N][MAX_N];
int ss[MAX_N][2][2];
int u, v;
int N, M;
str S[2];
int l;

void gss(int i, int j)
{
	if (i < 0 && j < 0) return;
	if (i >= 0 && GDP(i, j) == GDP(i - 1, j)) gss(i - 1, j);
	else if (j >= 0 && GDP(i, j) == GDP(i, j - 1)) gss(i, j - 1);
	else if (i >= 0 && j >= 0) ss[GDP(i, j) - 1][0][0] = i, ss[GDP(i, j) - 1][1][0] = j, gss(i - 1, j - 1);
}

void compact(int s)
{
	FORRI(ss[l][s][0], S[s].length() - 1) if (S[s][i] == S[s][ss[l][s][0]]) ss[l][s][1] = i;
	RROFI(l - 1, 0) FORR(j, ss[i][s][0], ss[i + 1][s][1] - 1)
		if (S[s][ss[i][s][0]] == S[s][j]) ss[i][s][1] = j;
}

void process()
{
	RNM >> S[0] >> S[1];
	FORRI(0, N - 1) FORR(j, 0, M - 1)
		DP[i][j] = S[0][i] == S[1][j] ? 1 + GDP(i - 1, j - 1) : max(GDP(i - 1, j), GDP(i, j - 1));
	l = DP[N - 1][M - 1] - 1;
	gss(N - 1, M - 1);
	compact(0), compact(1);
	int mx = 0;
	FORRI(0, l) FORR(j, i, l)
		mx = max(mx, 4 * (j - i + 1) - (max(j - i, ss[j][0][0] - ss[i][0][1]) + 1) - (max(j - i, ss[j][1][0] - ss[i][1][1]) + 1));
	OUTN(mx);
}

int main()
{
	ios_base::sync_with_stdio(false);
	SIN.tie(NULL);
	T = 1;
	//SIN >> T;
	FOR(t, T) process();
	cout << out;
	return 0;
}


#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <numeric>
#include <vector>
#include <string>
#include <cmath>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FORR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR(i, a) FORR(i, 1, a)
#define FORRI(a, b) FORR(i, a, b)
#define FORI(a) FOR(i, a)
#define FORIN FORI(N)

#define RROF(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ROF(i, a) RROF(i, a, 1)
#define RROFI(a, b) RROF(i, a, b)
#define ROFI(a) ROF(i, a)
#define ROFIN ROFI(N)

#define FORT(it, l) for (auto it = (l).begin(); it != (l).end();)
#define FORIT(l) FORT(it, l)

#define FORA(e, l) for (auto e : l)
#define FORE(l) FORA(e, l)

#define SIN cin
#define RN SIN >> N
#define RNM RN >> M
#define RARR(A, N) FORI(N) SIN >> A[i]
#define RARR2(A, N) RARR(A, N)[0] >> A[i][1]
#define RARR3(A, N) RARR2(A, N) >> A[i][2]
#define RARR0(A, N) FORRI(0, N - 1) SIN >> A[i]
#define RA RARR(A, N)
#define RA2 RARR2(A, N)
#define RA3 RARR3(A, N)
#define RA0 RARR0(A, N)
#define RNA RN; RA
#define RNA2 RN; RA2
#define RNA3 RN; RA3
#define RDADJ FORI(M) SIN >> u >> v, adj[u].insert(v)
#define RUADJ RDADJ, adj[v].insert(u)

#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x) memset(x, ~(char)0, sizeof(x))
#define SRT(l) sort(l.begin(), l.end())
#define SRTC(l, c) sort(l.begin(), l.end(), c)
#define SRTN(l) sort(l + 1, l + N + 1)
#define SRTNC(l, c) sort(l + 1, l + N + 1, c)
#define REV(l) reverse(l.begin(), l.end())
#define REVN(l) reverse(l + 1, l + N + 1)

#define SUM(l) accumulate(l.begin(), l.end(), 0)
#define SUMA(a, n) accumulate(a, a + n, 0)
#define SUMN(a) SUMA(a + 1, N)

#define MOD(x) (MOD_VAL + (x) % MOD_VAL) % MOD_VAL
#define MULT(x, y) MOD((lli)(x) * (lli)(y))
#define ADD(x, y) MOD((lli)(x) + (lli)(y))
#define INV(x) exp((x), MOD_VAL - 2)
#define MMULT(x, y) x = MULT(x, y)
#define MADD(x, y) x = ADD(x, y)
#define MOD_VAL 1000000007LL

#define MGET(m, k) [&](){ auto it = (m).find(k); return it == (m).end() ? 0 : it->se; }()
#define MINC(m, k, v) [&](){ auto it = (m).find(k); if (it == (m).end()) (m).insert({ (k), (v) }); else it->se += (v); }()

#define fi first
#define se second

#define CHNL out[out.length() - 1] = '\n'
#define OUTN(x) out += TOS(x), APNL
#define OUTS(x) out += TOS(x) + " "
#define OUTA(l) FORA(e, l) OUTS(e); CHNL
#define OUTF(a, n) FOR(i, n) OUTS((a)[i]); CHNL
#define APNL out += "\n"
#define TOS(x) to_string(x)

#define FAIL { out += "-1\n"; return; }

#define MAX_N 5001
#define NBT 32

typedef long double ld;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef set<int, bool(*)(int, int)> sic;
typedef set<pii, bool(*)(pii, pii)> spic;
typedef set<lli, bool(*)(lli, lli)> slc;
typedef set<pll, bool(*)(pll, pll)> splc;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<lli, lli> mll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef list<pii> lpi;
typedef list<pll> lpl;
typedef list<int> li;
typedef list<lli> ll;
typedef set<pii> spi;
typedef set<pll> spl;
typedef set<int> si;
typedef set<lli> sl;
typedef string str;

pii operator+(const pii& x, const pii& y) { return { x.fi + y.fi, x.se + y.se }; }
pll operator+(const pll& x, const pll& y) { return { x.fi + y.fi, x.se + y.se }; }

lli gcd(lli a, lli b) { return a >= b ? b ? gcd(b, a % b) : a : gcd(b, a); }
lli lcm(lli a, lli b) { return a / gcd(a, b) * b; }

lli exp(lli a, lli b)
{
	lli r = 1;
	while (b)
		MMULT(r, b & 1 ? a : 1), MMULT(a, a), b >>= 1;
	return r;
}

str out;
lli T;

#define GDP(i, j) (i < 0 || j < 0 ? 0 : DP[i][j])
si adj[MAX_N];
int DP[MAX_N][MAX_N];
int ss[MAX_N][2];
int u, v;
int N, M;
str S[2];

void gss(int i, int j)
{
	if (i < 0 && j < 0) return;
	if (i >= 0 && GDP(i, j) == GDP(i - 1, j)) gss(i - 1, j);
	else if (j >= 0 && GDP(i, j) == GDP(i, j - 1)) gss(i, j - 1);
	else if (i >= 0 && j >= 0) ss[GDP(i, j) - 1][0] = i, ss[GDP(i, j) - 1][1] = j, gss(i - 1, j - 1);
}

void compact(int s)
{
	RROFI(DP[N - 1][M - 1] - 2, 0) FORR(j, ss[i][s], ss[i + 1][s] - 1)
		if (S[s][ss[i][s]] == S[s][j]) ss[i][s] = j;
}

void process()
{
	RNM >> S[0] >> S[1];
	FORRI(0, N - 1) FORR(j, 0, M - 1)
		DP[i][j] = S[0][i] == S[1][j] ? 1 + GDP(i - 1, j - 1) : max(GDP(i - 1, j), GDP(i, j - 1));
	gss(N - 1, M - 1);
	compact(0), compact(1);
	int mx = 0;
	FORRI(0, DP[N - 1][M - 1] - 1) FORR(j, i, DP[N - 1][M - 1] - 1)
		mx = max(mx, 4 * (j - i + 1) - (ss[j][0] - ss[i][0] + 1) - (ss[j][1] - ss[i][1] + 1));
	OUTN(mx);
}

int main()
{
	ios_base::sync_with_stdio(false);
	SIN.tie(NULL);
	T = 1;
	//SIN >> T;
	FOR(t, T) process();
	cout << out;
	return 0;
}


#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <numeric>
#include <vector>
#include <string>
#include <cmath>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FORR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR(i, a) FORR(i, 1, a)
#define FORRI(a, b) FORR(i, a, b)
#define FORI(a) FOR(i, a)
#define FORIN FORI(N)

#define RROF(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ROF(i, a) RROF(i, a, 1)
#define RROFI(a, b) RROF(i, a, b)
#define ROFI(a) ROF(i, a)
#define ROFIN ROFI(N)

#define FORT(it, l) for (auto it = (l).begin(); it != (l).end();)
#define FORIT(l) FORT(it, l)

#define FORA(e, l) for (auto e : l)
#define FORE(l) FORA(e, l)

#define SIN cin
#define RN SIN >> N
#define RNM RN >> M
#define RARR(A, N) FORI(N) SIN >> A[i]
#define RARR2(A, N) RARR(A, N)[0] >> A[i][1]
#define RARR3(A, N) RARR2(A, N) >> A[i][2]
#define RARR0(A, N) FORRI(0, N - 1) SIN >> A[i]
#define RA RARR(A, N)
#define RA2 RARR2(A, N)
#define RA3 RARR3(A, N)
#define RA0 RARR0(A, N)
#define RNA RN; RA
#define RNA2 RN; RA2
#define RNA3 RN; RA3
#define RDADJ FORI(M) SIN >> u >> v, adj[u].insert(v)
#define RUADJ RDADJ, adj[v].insert(u)

#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x) memset(x, ~(char)0, sizeof(x))
#define SRT(l) sort(l.begin(), l.end())
#define SRTC(l, c) sort(l.begin(), l.end(), c)
#define SRTN(l) sort(l + 1, l + N + 1)
#define SRTNC(l, c) sort(l + 1, l + N + 1, c)
#define REV(l) reverse(l.begin(), l.end())
#define REVN(l) reverse(l + 1, l + N + 1)

#define SUM(l) accumulate(l.begin(), l.end(), 0)
#define SUMA(a, n) accumulate(a, a + n, 0)
#define SUMN(a) SUMA(a + 1, N)

#define MOD(x) (MOD_VAL + (x) % MOD_VAL) % MOD_VAL
#define MULT(x, y) MOD((lli)(x) * (lli)(y))
#define ADD(x, y) MOD((lli)(x) + (lli)(y))
#define INV(x) exp((x), MOD_VAL - 2)
#define MMULT(x, y) x = MULT(x, y)
#define MADD(x, y) x = ADD(x, y)
#define MOD_VAL 1000000007LL

#define MGET(m, k) [&](){ auto it = (m).find(k); return it == (m).end() ? 0 : it->se; }()
#define MINC(m, k, v) [&](){ auto it = (m).find(k); if (it == (m).end()) (m).insert({ (k), (v) }); else it->se += (v); }()

#define fi first
#define se second

#define CHNL out[out.length() - 1] = '\n'
#define OUTN(x) out += TOS(x), APNL
#define OUTS(x) out += TOS(x) + " "
#define OUTA(l) FORA(e, l) OUTS(e); CHNL
#define OUTF(a, n) FOR(i, n) OUTS((a)[i]); CHNL
#define APNL out += "\n"
#define TOS(x) to_string(x)

#define FAIL { out += "-1\n"; return; }

#define MAX_N 10000
#define NBT 32

typedef long double ld;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef set<int, bool(*)(int, int)> sic;
typedef set<pii, bool(*)(pii, pii)> spic;
typedef set<lli, bool(*)(lli, lli)> slc;
typedef set<pll, bool(*)(pll, pll)> splc;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<lli, lli> mll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef list<pii> lpi;
typedef list<pll> lpl;
typedef list<int> li;
typedef list<lli> ll;
typedef set<pii> spi;
typedef set<pll> spl;
typedef set<int> si;
typedef set<lli> sl;
typedef string str;

pii operator+(const pii& x, const pii& y) { return { x.fi + y.fi, x.se + y.se }; }
pll operator+(const pll& x, const pll& y) { return { x.fi + y.fi, x.se + y.se }; }

lli gcd(lli a, lli b) { return a >= b ? b ? gcd(b, a % b) : a : gcd(b, a); }
lli lcm(lli a, lli b) { return a / gcd(a, b) * b; }

lli exp(lli a, lli b)
{
	lli r = 1;
	while (b)
		MMULT(r, b & 1 ? a : 1), MMULT(a, a), b >>= 1;
	return r;
}

str out;
lli T;

#define GDP(i, j) (i < 0 || j < 0 ? 0 : DP[i][j])
si adj[MAX_N];
int DP[MAX_N][MAX_N];
int ss[MAX_N][2];
int u, v;
int N, M;
str S[2];

void gss(int i, int j)
{
	if (i < 0 && j < 0) return;
	if (i >= 0 && GDP(i, j) == GDP(i - 1, j)) gss(i - 1, j);
	else if (j >= 0 && GDP(i, j) == GDP(i, j - 1)) gss(i, j - 1);
	else if (i >= 0 && j >= 0) ss[GDP(i, j) - 1][0] = i, ss[GDP(i, j) - 1][1] = j, gss(i - 1, j - 1);
}

void compact(int s)
{
	RROFI(DP[N - 1][M - 1] - 2, 0) FORR(j, ss[i][s], ss[i + 1][s] - 1)
		if (S[s][ss[i][s]] == S[s][j]) ss[i][s] = j;
}

void process()
{
	RNM >> S[0] >> S[1];
	FORRI(0, N - 1) FORR(j, 0, M - 1)
		DP[i][j] = S[0][i] == S[1][j] ? 1 + GDP(i - 1, j - 1) : max(GDP(i - 1, j), GDP(i, j - 1));
	gss(N - 1, M - 1);
	compact(0), compact(1);
	int mx = 0;
	FORRI(0, DP[N - 1][M - 1] - 1) FORR(j, i, DP[N - 1][M - 1] - 1)
		mx = max(mx, 4 * (j - i + 1) - (ss[j][0] - ss[i][0] + 1) - (ss[j][1] - ss[i][1] + 1));
	OUTN(mx);
}

int main()
{
	ios_base::sync_with_stdio(false);
	SIN.tie(NULL);
	T = 1;
	//SIN >> T;
	FOR(t, T) process();
	cout << out;
	return 0;
}


#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <numeric>
#include <vector>
#include <string>
#include <cmath>
#include <list>
#include <set>
#include <map>

using namespace std;

#define FORR(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)
#define FOR(i, a) FORR(i, 1, a)
#define FORRI(a, b) FORR(i, a, b)
#define FORI(a) FOR(i, a)
#define FORIN FORI(N)

#define RROF(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define ROF(i, a) RROF(i, a, 1)
#define RROFI(a, b) RROF(i, a, b)
#define ROFI(a) ROF(i, a)
#define ROFIN ROFI(N)

#define FORT(it, l) for (auto it = (l).begin(); it != (l).end();)
#define FORIT(l) FORT(it, l)

#define FORA(e, l) for (auto e : l)
#define FORE(l) FORA(e, l)

#define SIN cin
#define RN SIN >> N
#define RNM RN >> M
#define RARR(A, N) FORI(N) SIN >> A[i]
#define RARR2(A, N) RARR(A, N)[0] >> A[i][1]
#define RARR3(A, N) RARR2(A, N) >> A[i][2]
#define RARR0(A, N) FORRI(0, N - 1) SIN >> A[i]
#define RA RARR(A, N)
#define RA2 RARR2(A, N)
#define RA3 RARR3(A, N)
#define RA0 RARR0(A, N)
#define RNA RN; RA
#define RNA2 RN; RA2
#define RNA3 RN; RA3
#define RDADJ FORI(M) SIN >> u >> v, adj[u].insert(v)
#define RUADJ RDADJ, adj[v].insert(u)

#define CLEAR(x) memset(x, 0, sizeof(x))
#define FILL(x) memset(x, ~(char)0, sizeof(x))
#define SRT(l) sort(l.begin(), l.end())
#define SRTC(l, c) sort(l.begin(), l.end(), c)
#define SRTN(l) sort(l + 1, l + N + 1)
#define SRTNC(l, c) sort(l + 1, l + N + 1, c)
#define REV(l) reverse(l.begin(), l.end())
#define REVN(l) reverse(l + 1, l + N + 1)

#define SUM(l) accumulate(l.begin(), l.end(), 0)
#define SUMA(a, n) accumulate(a, a + n, 0)
#define SUMN(a) SUMA(a + 1, N)

#define MOD(x) (MOD_VAL + (x) % MOD_VAL) % MOD_VAL
#define MULT(x, y) MOD((lli)(x) * (lli)(y))
#define ADD(x, y) MOD((lli)(x) + (lli)(y))
#define INV(x) exp((x), MOD_VAL - 2)
#define MMULT(x, y) x = MULT(x, y)
#define MADD(x, y) x = ADD(x, y)
#define MOD_VAL 1000000007LL

#define MGET(m, k) [&](){ auto it = (m).find(k); return it == (m).end() ? 0 : it->se; }()
#define MINC(m, k, v) [&](){ auto it = (m).find(k); if (it == (m).end()) (m).insert({ (k), (v) }); else it->se += (v); }()

#define fi first
#define se second

#define CHNL out[out.length() - 1] = '\n'
#define OUTN(x) out += TOS(x), APNL
#define OUTS(x) out += TOS(x) + " "
#define OUTA(l) FORA(e, l) OUTS(e); CHNL
#define OUTF(a, n) FOR(i, n) OUTS((a)[i]); CHNL
#define APNL out += "\n"
#define TOS(x) to_string(x)

#define FAIL { out += "-1\n"; return; }

#define MAX_N 5001
#define NBT 32

typedef long double ld;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef set<int, bool(*)(int, int)> sic;
typedef set<pii, bool(*)(pii, pii)> spic;
typedef set<lli, bool(*)(lli, lli)> slc;
typedef set<pll, bool(*)(pll, pll)> splc;
typedef map<string, int> msi;
typedef map<int, int> mii;
typedef map<lli, lli> mll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef list<pii> lpi;
typedef list<pll> lpl;
typedef list<int> li;
typedef list<lli> ll;
typedef set<pii> spi;
typedef set<pll> spl;
typedef set<int> si;
typedef set<lli> sl;
typedef string str;

pii operator+(const pii& x, const pii& y) { return { x.fi + y.fi, x.se + y.se }; }
pll operator+(const pll& x, const pll& y) { return { x.fi + y.fi, x.se + y.se }; }

lli gcd(lli a, lli b) { return a >= b ? b ? gcd(b, a % b) : a : gcd(b, a); }
lli lcm(lli a, lli b) { return a / gcd(a, b) * b; }

lli exp(lli a, lli b)
{
	lli r = 1;
	while (b)
		MMULT(r, b & 1 ? a : 1), MMULT(a, a), b >>= 1;
	return r;
}

str out;
lli T;

#define GDP(i, j) (i < 0 || j < 0 ? 0 : DP[i][j])
si adj[MAX_N];
int DP[MAX_N][MAX_N];
int ss[MAX_N][2][2];
int u, v;
int N, M;
str S[2];

void process()
{
	RNM >> S[0] >> S[1];
	FORRI(0, N - 1) FORR(j, 0, M - 1)
		u = max(u, DP[i][j] = max(0, S[0][i] == S[1][j] ? 2 + GDP(i - 1, j - 1) : max(GDP(i - 1, j) - 1, GDP(i, j - 1) - 1)));
	OUTN(u);
}

int main()
{
	ios_base::sync_with_stdio(false);
	SIN.tie(NULL);
	T = 1;
	//SIN >> T;
	FOR(t, T) process();
	cout << out;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5000;
int n, m;
string a, b;
int dp[MAXN+1][MAXN+1];
int ans;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  for (int i = n-1; i >= 0; i--) {
    for (int j = m-1; j >= 0; j--) {
      dp[i][j] = (a[i] == b[j] ? 2 : -2) + max(dp[i+1][j+1], 0);
      ans = max(ans, dp[i][j]);
      if (j+1 < m)
        dp[i][j] = max(dp[i][j], dp[i][j+1] - 1);
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5000;
int n, m;
string a, b;
int dp[MAXN+1][MAXN+1];
int ans;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  for (int i = n-1; i >= 0; i--) {
    for (int j = m-1; j >= 0; j--) {
      dp[i][j] = (a[i] == b[j] ? 2 : -2) + dp[i+1][j+1];
      dp[i][j] = max(dp[i][j], 0);
      ans = max(ans, dp[i][j]);
      dp[i][j] = max(dp[i][j], dp[i][j+1] - 1);
      dp[i][j] = max(dp[i][j], dp[i+1][j] - 1);
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5000;
int n, m;
string a, b;
int dp[MAXN+1][MAXN+1];
int ans;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  cin >> a >> b;
  for (int i = n-1; i >= 0; i--) {
    for (int j = m-1; j >= 0; j--) {
      dp[i][j] = (a[i] == b[j] ? 2 : -2) + max(dp[i+1][j+1], 0);
      ans = max(ans, dp[i][j]);
      dp[i][j] = max(dp[i][j], dp[i][j+1] - 1);
    }
  }
  cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
// #define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15

/* Debug Begins */
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{";
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r;
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/

signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {
        int n,m;
        cin >> n >> m;
        string s,t;
        cin >> s >> t;
        s = '0' + s;
        t = '0' + t;
        int dp[n+1][m+1];
        rep(i,0,n+1){
            rep(j,0,m+1) dp[i][j] = 0;
        }
        vector<int> inds[26], indt[26];
        for(int i = 1; i <= n; i++){
            inds[s[i]-'a'].pb(i);
        }
        for(int i = 1; i <= m; i++){
            indt[t[i]-'a'].pb(i);
        }
        int lasts[n+1][26], lastt[m+1][26];
        rep(i,0,n+1){
            rep(j,0,26){
                if(i == 0){
                    lasts[i][j] = -1;
                    continue;
                }
                if(s[i] == 'a' + j) lasts[i][j] = i;
                else lasts[i][j] = lasts[i-1][j];
            }
        }
        rep(i,0,m+1){
            rep(j,0,26){
                if(i == 0){
                    lastt[i][j] = -1;
                    continue;
                }
                if(t[i] == 'a' + j) lastt[i][j] = i;
                else lastt[i][j] = lastt[i-1][j];
            }
        }
        rep(i,1,n+1){
            rep(j,1,m+1){
                dp[i][j] = max({dp[i][j],dp[i-1][j]-1, dp[i][j-1]-1});
                int k1 = lastt[j][s[i]-'a'], k2 = lasts[i][t[j]-'a'];
                if(k1 != -1){
                    dp[i][j] = max(dp[i][j], dp[i-1][k1-1] + 4 - 1 - (j - k1 + 1));
                }
                if(k2 != -1){
                    dp[i][j] = max(dp[i][j], dp[k2-1][j-1] + 4 - 1 - (i - k2 + 1));
                }
            }
        }
        int ans = 0;
        rep(i,1,n+1) rep(j,1,m+1) ans = max(ans, dp[i][j]);
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15

/* Debug Begins */
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{";
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r;
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
/***************************************************************/

signed main()
{
    ios_base::sync_with_stdio(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {
        int n,m;
        cin >> n >> m;
        string s,t;
        cin >> s >> t;
        s = '0' + s;
        t = '0' + t;
        int dp[n+1][m+1];
        rep(i,0,n+1){
            rep(j,0,m+1) dp[i][j] = 0;
        }
        vector<int> inds[26], indt[26];
        for(int i = 1; i <= n; i++){
            inds[s[i]-'a'].pb(i);
        }
        for(int i = 1; i <= m; i++){
            indt[t[i]-'a'].pb(i);
        }
        rep(i,1,n+1){
            rep(j,1,m+1){
                dp[i][j] = max({dp[i][j],dp[i-1][j]-1, dp[i][j-1]-1});
                int k1 = -1, k2 = -1;
                auto it = upper_bound(all(indt[s[i]-'a']), j);
                if(it != indt[s[i]-'a'].begin()){
                    it--;
                    k1 = *it;
                }
                it = upper_bound(all(inds[t[j]-'a']), i);
                if(it != inds[t[j]-'a'].begin()){
                    it--;
                    k2 = *it;
                }
                if(k1 != -1){
                    dp[i][j] = max(dp[i][j], dp[i-1][k1-1] + 4 - 1 - (j - k1 + 1));
                }
                if(k2 != -1){
                    dp[i][j] = max(dp[i][j], dp[k2-1][j-1] + 4 - 1 - (i - k2 + 1));
                }
            }
        }
        int ans = 0;
        rep(i,1,n+1) rep(j,1,m+1) ans = max(ans, dp[i][j]);
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

const int N = 5005;
int dp[N][N], n, m;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i] == t[j]) dp[i][j] = (dp[i - 1][j - 1] + 2);
            else dp[i][j] = max(dp[i - 1][j] - 1, dp[i][j - 1] - 1);
            // cout << dp[i][j] << ' ';
        }
        // cout << '\n';
    }

    int mx = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) mx = max(mx, dp[i][j]);
    }

    cout << mx << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

const int N = 5005;
int dp[N][N], n, m;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;

    for (int i = 1; i < N; i++) {
        dp[0][i] = dp[i][0] = -1;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i] == t[j]) dp[i][j] = max(dp[i - 1][j - 1] + 2, 2);
            else dp[i][j] = max({dp[i - 1][j] - 1, dp[i][j - 1] - 1, -2});
            // cout << dp[i][j] << ' ';
        }
        // cout << '\n';
    }

    int mx = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) mx = max(mx, dp[i][j]);
    }

    cout << mx << '\n';

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    int arr[a+1][b+1];
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) arr[i][j]=0;
    }
    string s,s2;
    cin >> s >> s2;
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++){
            if (s[i+1]==s2[j+1]) arr[i+1][j+1]=max(arr[i+1][j+1],arr[i][j]+2);
            arr[i+1][j]=max(arr[i+1][j],arr[i][j]-1);
            arr[i][j+1]=max(arr[i][j+1],arr[i][j]-1);
            ans=max(arr[i][j+1],max(arr[i+1][j+1],arr[i+1][j]));
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    int arr[a+1][b+1];
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) arr[i][j]=0;
    }
    string s,s2;
    cin >> s >> s2;
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++){
            if (s[i+1]==s2[j+1]) arr[i+1][j+1]=max(arr[i+1][j+1],arr[i][j]+2);
            arr[i+1][j]=max(arr[i+1][j],arr[i][j]-1);
            arr[i][j+1]=max(arr[i][j+1],arr[i][j]-1);
            ans=max(arr[i][j+1],max(arr[i+1][j+1],arr[i+1][j]))
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    int arr[a][b];
    string s,s2;
    cin >> s >> s2;
    for (int i=0;i<a;i++){
        for (int j=0;j<b;j++){
            arr[i][j]=0;
            if (i!=0 and j!=0 and s[i]==s2[j]) arr[i][j]=arr[i-1][j-1]+2;
            if (i!=0) arr[i][j]=max(arr[i][j],arr[i-1][j]-1);
            if (j!=0) arr[i][j]=max(arr[i][j],arr[i][j-1]-1);
            ans=max(ans,arr[i][j]);
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    int arr[a+1][b+1];
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) arr[i][j]=0;
    }
    string s,s2;
    cin >> s >> s2;
    for (int i=0;i<a;i++){
        for (int j=0;j<b;j++){
            if (s[i+1]==s2[j+1]) arr[i+1][j+1]=max(arr[i+1][j+1],arr[i][j]+2);
            arr[i+1][j]=max(arr[i+1][j],arr[i][j]-1);
            arr[i][j+1]=max(arr[i][j+1],arr[i][j]-1);
            ans=max(arr[i][j+1],max(arr[i+1][j+1],arr[i+1][j]));
        }
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    int arr[a+1][b+1];
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) arr[i][j]=0;
    }
    string s,s2;
    cin >> s >> s2;
    for (int i=0;i<a;i++){
        for (int j=0;j<b;j++){
            if (s[i+1]==s2[j+1]) arr[i+1][j+1]=max(arr[i+1][j+1],arr[i][j]+2);
            arr[i+1][j]=max(arr[i+1][j],arr[i][j]-1);
            arr[i][j+1]=max(arr[i][j+1],arr[i][j]-1);
        }
    }
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) ans=max(ans,arr[i][j]);
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,ans=0;
    cin >> a >> b;
    int arr[a+1][b+1];
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) arr[i][j]=0;
    }
    string s,s2;
    cin >> s >> s2;
    for (int i=0;i<a;i++){
        for (int j=0;j<b;j++){
            if (s[i]==s2[j]) arr[i+1][j+1]=max(arr[i+1][j+1],arr[i][j]+2);
            arr[i+1][j]=max(arr[i+1][j],arr[i][j]-1);
            arr[i][j+1]=max(arr[i][j+1],arr[i][j]-1);
        }
    }
    for (int i=0;i<=a;i++){
        for (int j=0;j<=b;j++) ans=max(ans,arr[i][j]);
    }
    cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
//const ld PI=acosl(-1),EPS=1e-10;
template<class T> inline void dmin(T& x,T y){ y<x?x=y:0; }
template<class T> inline void dmax(T& x,T y){ y>x?x=y:0; }
template<class T> inline void dmin(T& x,vector<T> y){for(auto t:y)t<x?x=t:0;}
template<class T> inline void dmax(T& x,vector<T> y){for(auto t:y)t>x?x=t:0;}
/*
const int N=5+1e5,MOD=998244353;
inline int fpow(int x,int n,int ret=1,int mod=MOD){
	for(;n;n>>=1,x=1ll*x*x%mod)
		n&1?ret=1ll*ret*x%mod:0;
	return ret;
}
inline void mo(int& x){ x>=MOD?x-=MOD:0; }
inline int mo1(int x){ return x>=MOD?x-MOD:x; }
int inv[N],fac[N],ifac[N];
struct IniterFacInv{
	IniterFacInv(){
		fac[0]=ifac[0]=inv[1]=1;
		for(int i=1;i<N;++i){
			fac[i]=1ll*fac[i-1]*i%MOD;
			if(i>1) inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
			ifac[i]=1ll*ifac[i-1]*inv[i]%MOD;
		}
	}
}__initer_comb;
inline int comb(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return 1ll*fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;
}
inline int rcomb(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return 1ll*ifac[n]*fac[m]%MOD*fac[n-m]%MOD;
}
*/
const int N=5005;
char a[N],b[N];
int f[N][N];
int main(){
	int n,m; cin>>n>>m;
	scanf("%s",a+1);
	scanf("%s",b+1);
	f[0][0]=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j){
			if(a[i]==b[j])
				f[i][j]=max(2,f[i-1][j-1]+2);
			f[i][j]=max({f[i][j],f[i-1][j]-1,f[i][j-1]-1});
		}
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			ans=max(ans,f[i][j]);
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
//const ld PI=acosl(-1),EPS=1e-10;
template<class T> inline void dmin(T& x,T y){ y<x?x=y:0; }
template<class T> inline void dmax(T& x,T y){ y>x?x=y:0; }
template<class T> inline void dmin(T& x,vector<T> y){for(auto t:y)t<x?x=t:0;}
template<class T> inline void dmax(T& x,vector<T> y){for(auto t:y)t>x?x=t:0;}
/*
const int N=5+1e5,MOD=998244353;
inline int fpow(int x,int n,int ret=1,int mod=MOD){
	for(;n;n>>=1,x=1ll*x*x%mod)
		n&1?ret=1ll*ret*x%mod:0;
	return ret;
}
inline void mo(int& x){ x>=MOD?x-=MOD:0; }
inline int mo1(int x){ return x>=MOD?x-MOD:x; }
int inv[N],fac[N],ifac[N];
struct IniterFacInv{
	IniterFacInv(){
		fac[0]=ifac[0]=inv[1]=1;
		for(int i=1;i<N;++i){
			fac[i]=1ll*fac[i-1]*i%MOD;
			if(i>1) inv[i]=1ll*(MOD-MOD/i)*inv[MOD%i]%MOD;
			ifac[i]=1ll*ifac[i-1]*inv[i]%MOD;
		}
	}
}__initer_comb;
inline int comb(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return 1ll*fac[n]*ifac[m]%MOD*ifac[n-m]%MOD;
}
inline int rcomb(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return 1ll*ifac[n]*fac[m]%MOD*fac[n-m]%MOD;
}
*/
const int N=5005;
char a[N],b[N];
int f[N][N];
int main(){
	int n,m; cin>>n>>m;
	scanf("%s",a+1);
	scanf("%s",b+1);
	f[0][0]=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j){
			if(a[i]==b[j])
				f[i][j]=max(2,f[i-1][j-1]+2);
			f[i][j]=max({f[i][j],f[i-1][j]-1,f[i][j-1]-1});
		}
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			ans=max(ans,f[i][j]);
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e3+100;

int dp[maxn][maxn];
int n, m;
char a[maxn], b[maxn];

int main()
{
    int ans = 0;
    //freopen("inp.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i] == b[j])
            {
                dp[i][j] = dp[i-1][j-1]+2;
            } else
            {
                dp[i][j] = max(max(dp[i-1][j], dp[i][j-1])-1, dp[i][j]);
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e3+100;

int dp[maxn][maxn];
int n, m;
char a[maxn], b[maxn];

int main()
{
    int ans = 0;
    //freopen("inp.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (a[i] == b[j])
            {
                dp[i][j] = dp[i-1][j-1]+2;
            } else
            {
                dp[i][j] = max(max(dp[i-1][j], dp[i][j-1])-1, dp[i][j]);
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}


/* winners never quit and quitters never win.
      #swap                                 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pql priority_queue<ll>
#define pqh priority_queue<ll,vc<ll>,greater<ll>>
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt(),m=nxt();
    string s,s1;
    cin>>s>>s1;
    ll dp[n+1][m+1],temp[n+1][m+1];
    rep(a,0,n+1)
    {
        rep(b,0,m+1)
        {
            dp[a][b]=0;
            temp[a][b]=0;
        }
    }
    ll ans=0;
    rep(a,1,n+1)
    {
        rep(b,1,m+1)
        {
            if(s[a-1]==s1[b-1])
            {
                dp[a][b]=max(2*1LL,dp[a-1][b-1]+2);
            }
            else
            {
                dp[a][b]=max(0*1LL,max(dp[a-1][b],dp[a][b-1])-1);

            }
            ans=max(ans,dp[a][b]);
        }
    }
    cout<<ans<<endl;
	printclock;
	return 0;
}


/* winners never quit and quitters never win.
      #swap                                 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

template <typename T>
void make_unique(vector<T>& vec) {
  sort(all(vec));
  vec.erase(unique(all(vec)), vec.end());
}

#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pql priority_queue<ll>
#define pqh priority_queue<ll,vc<ll>,greater<ll>>
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll>
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll dp[2][5005];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n=nxt(),m=nxt();
    string s,s1;
    cin>>s>>s1;
    rep(a,0,2)
    {
        rep(b,0,m+1)
        {
            dp[a][b]=0;
        }
    }
    ll ans=0;
    rep(a,1,n+1)
    {
        ll curr=(a&1LL);
        ll prev=(curr^1LL);
        rep(b,1,m+1)
        {
            if(s[a-1]==s1[b-1])
            {
                dp[curr][b]=max(2*1LL,dp[prev][b-1]+2);
            }
            else
            {
                dp[curr][b]=max(0*1LL,max(dp[prev][b],dp[curr][b-1])-1);

            }
            ans=max(ans,dp[curr][b]);
        }
    }
    cout<<ans<<endl;
	printclock;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define MEM(x,val) memset(x,val,sizeof(x))
#define LL long long
#define F first
#define S second
#define PI pair<int,int>
#define PLL pair<LL,LL>
#define ALL(x) x.begin(),x.end()

#define int LL

int N,M;
string s,t;

int calc(int i,int j){
  if(i >= N or j >= M){
    return 0;
  }
  int ans = 0;

  if(s[i] == t[j]){
    ans = max(ans,calc(i+1,j+1) + 2);
  }else{
    ans = max(ans,calc(i,j+1) - 1);
    ans = max(ans,calc(i+1,j) - 1);
  }
  return ans;
}

void solve(){
  cin >> N >> M;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0; i<N; i++){
    for(int j = 0; j<M; j++){
      ans = max(ans,calc(i,j));
    }
  }
  cout << ans << endl;
}

int32_t main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  int tt; tt = 1;
  int cas = 1;
  while(tt--){
    //printf("Case %d:\n",cas++);
    solve();
  }
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define MEM(x,val) memset(x,val,sizeof(x))
#define LL long long
#define F first
#define S second
#define PI pair<int,int>
#define PLL pair<LL,LL>
#define ALL(x) x.begin(),x.end()

#define int LL

int N,M;
string s,t;
int dp[5005][5005];

int calc(int i,int j){
  if(i >= N or j >= M){
    return 0;
  }
  int ans = 0;
  int &ret = dp[i][j];
  if(ret != -1) return ret;

  if(s[i] == t[j]){
    ans = max(ans,calc(i+1,j+1) + 2);
  }else{
    ans = max(ans,calc(i,j+1) - 1);
    ans = max(ans,calc(i+1,j) - 1);
  }
  return ret = ans;
}

void solve(){
  cin >> N >> M;
  cin >> s >> t;
  int ans = 0;
  MEM(dp,-1);
  for(int i = 0; i<N; i++){
    for(int j = 0; j<M; j++){
      ans = max(ans,calc(i,j));
    }
  }
  cout << ans << endl;
}

int32_t main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  int tt; tt = 1;
  int cas = 1;
  while(tt--){
    //printf("Case %d:\n",cas++);
    solve();
  }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    int a[m+1][n+1],ans=0;
    string x,y;
    cin>>x>>y;
    for(int i=0; i<=n; i++)
    {
        a[0][i]=0;
    }
    for(int i=0; i<=m; i++)
    {
        a[i][0]=0;
    }
    for(int i=1; i<=m; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if(y[i-1]==x[j-1])
            {
                a[i][j]=2+a[i-1][j-1];
                ans=max(a[i][j],ans);
            }
            else
            {
                a[i][j]=max(0,max(a[i-1][j]-1,a[i][j-1]-1));
                ans=max(a[i][j],ans);
            }
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;

/*Immortal Bird*/

#define int long long
#define LL long long
#define ULL usigned long long

#define I inline
#define Ri register int
#define For(i,a,b) for(Ri i=(a);i<=(b);++i)
#define Dow(i,a,b) for(Ri i=(a);i>=(b);--i)
#define Go(i,u) for(Ri i=lnk[u];i;i=e[i].nxt)
#define go(i,u) for(Ri i=head[u];i;i=nxt[i])
#define Mem(f,x) memset(f,x,sizeof(f))
#define Pii pair<int,int>
#define Mp make_pair
#define Fi first
#define Se second
#define Pb push_back

I int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}

I void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+48);
}

I void writebl(int x){
	write(x);putchar(' ');
}

I void writeln(int x){
	write(x);putchar('\n');
}

const int N = 5e3+5;

int f[N][N];
char a[N], b[N];

signed main(){
	int n = read(), m = read();
	scanf("%s",a+1);
	scanf("%s",b+1);
	int ans = 0;
	For(i, 1, n){
		For(j, 1, n){
			if(a[i] == b[j])
			f[i][j] = max(f[i-1][j-1]+4-2, f[i][j]);
			f[i][j] = max(f[i][j],f[i-1][j]-1);
			f[i][j] = max(f[i][j],f[i][j-1]-1);
			ans = max(ans, f[i][j]);
		}
	}
	writeln(ans);
}


#include<bits/stdc++.h>
using namespace std;

/*Immortal Bird*/

#define int long long
#define LL long long
#define ULL usigned long long

#define I inline
#define Ri register int
#define For(i,a,b) for(Ri i=(a);i<=(b);++i)
#define Dow(i,a,b) for(Ri i=(a);i>=(b);--i)
#define Go(i,u) for(Ri i=lnk[u];i;i=e[i].nxt)
#define go(i,u) for(Ri i=head[u];i;i=nxt[i])
#define Mem(f,x) memset(f,x,sizeof(f))
#define Pii pair<int,int>
#define Mp make_pair
#define Fi first
#define Se second
#define Pb push_back

I int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}

I void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+48);
}

I void writebl(int x){
	write(x);putchar(' ');
}

I void writeln(int x){
	write(x);putchar('\n');
}

const int N = 5e3+5;

int f[N][N];
char a[N], b[N];

signed main(){
	int n = read(), m = read();
	scanf("%s",a+1);
	scanf("%s",b+1);
	int ans = 0;
	For(i, 1, n){
		For(j, 1, n){
			if(a[i] == b[j])
			f[i][j] = f[i-1][j-1]+4-2;
			f[i][j] = max(f[i][j],f[i-1][j]-1);
			f[i][j] = max(f[i][j],f[i][j-1]-1);
			ans = max(ans, f[i][j]);
		}
	}
	writeln(ans);
}


#include<bits/stdc++.h>
using namespace std;

/*Immortal Bird*/

#define int long long
#define LL long long
#define ULL usigned long long

#define I inline
#define Ri register int
#define For(i,a,b) for(Ri i=(a);i<=(b);++i)
#define Dow(i,a,b) for(Ri i=(a);i>=(b);--i)
#define Go(i,u) for(Ri i=lnk[u];i;i=e[i].nxt)
#define go(i,u) for(Ri i=head[u];i;i=nxt[i])
#define Mem(f,x) memset(f,x,sizeof(f))
#define Pii pair<int,int>
#define Mp make_pair
#define Fi first
#define Se second
#define Pb push_back

I int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
	return f?-x:x;
}

I void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+48);
}

I void writebl(int x){
	write(x);putchar(' ');
}

I void writeln(int x){
	write(x);putchar('\n');
}

const int N = 5e3+5;

int f[N][N];
char a[N], b[N];

signed main(){
	int n = read(), m = read();
	scanf("%s",a+1);
	scanf("%s",b+1);
	int ans = 0;
	For(i, 1, n){
		For(j, 1, m){
			if(a[i] == b[j])
			f[i][j] = f[i-1][j-1]+4-2;
			f[i][j] = max(f[i][j],f[i-1][j]-1);
			f[i][j] = max(f[i][j],f[i][j-1]-1);
			ans = max(ans, f[i][j]);
		}
	}
	writeln(ans);
}


#include <bits/stdc++.h>
using namespace std;
//{
    #ifdef lawfung
    #define debug(...) do {\
        fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
        _DO(__VA_ARGS__);\
    }while(0)
    template<typename I> void _DO(I&&x) {cerr << x << '\n';}
    template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
    #define IOS
    #else
    #define debug(...)
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0)
    #endif
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;
    typedef pair<double,double> pdd;
    typedef long double ld;
    #define F first
    #define S second
    #define ALL(x)  (x).begin(),(x).end()
    #define SZ(x)   (ll)x.size()
    #define pb push_back
    #define eb emplace_back
    #define stp setprecision(30)<<fixed
    #define mdel(m, x) do{if(--m[x] == 0)m.erase(x);}while(0)
    #define mexi(m, x) (m.find(x) != m.end())
    #define mmin(m) (m.begin()->F)
    #define mmax(m) (m.rbegin()->F)
    #define LS(x) ((x<<1)+1)
    #define RS(x) ((x+1)<<1)
    const int NF = 0x3f3f3f3f;
    const ll INF = 0x3f3f3f3f3f3f3f3f;
    const ll MO7 = 1e9 + 7;
    const ll MO9 = 1e9 + 9;
    const ll MO87 = 1e9 + 87;
    const ll MO93 = 1e9 + 93;
    const ll MO53 = 998244353;
    const ld PI = 3.14159265358979323846264338327950288;
    const ld eps = 1e-7;
//}
const ll MAX = 5e3 + 6, Mlg = __lg(MAX) + 2;
int n, m;
string s1, s2;
int dp[MAX][MAX];
int nxt[2][MAX][26];
int que(int x, int y) {
    if(dp[x][y] != -1)  return dp[x][y];
    int ma = 2;
    for(int j = 0; j < 26; ++ j) {
        if(nxt[0][x][j] != -1 && nxt[1][y][j] != -1) {
            ma = max(ma, que(nxt[0][x][j], nxt[1][y][j]) + 4 - nxt[0][x][j] - nxt[1][y][j] + x + y );
        }
    }
    return dp[x][y] = ma;
}
int main() {
    IOS;
    cin >> n >> m;
    cin >> s1 >> s2;
    memset(dp, -1, sizeof dp);
    memset(nxt, -1, sizeof nxt);
    for(int i = n - 2; i >= 0; -- i) {
        for(int j = 0; j < 26; ++ j)
            nxt[0][i][j] = nxt[0][i + 1][j];
        nxt[0][i][s1[i + 1] - 'a'] = i + 1;
    }
    for(int i = m - 2; i >= 0; -- i) {
        for(int j = 0; j < 26; ++ j) {
            nxt[1][i][j] = nxt[1][i + 1][j];
        }
        nxt[1][i][s2[i + 1] - 'a'] = i + 1;
    }
    int ma = 0;
    for(int i = 0; i < n; ++ i) {
        for(int j = 0; j < m; ++ j) {
            if(s1[i] == s2[j])
                ma = max(ma, que(i, j));
        }
    }
    cout << ma << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//{
    #ifdef lawfung
    #define debug(...) do {\
        fprintf(stderr, "%s - %d : (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
        _DO(__VA_ARGS__);\
    }while(0)
    template<typename I> void _DO(I&&x) {cerr << x << '\n';}
    template<typename I, typename ...T> void _DO(I&&x,T&&...tail) {cerr << x << ", "; _DO(tail...);}
    #define IOS
    #else
    #define debug(...)
    #define IOS ios_base::sync_with_stdio(0);cin.tie(0)
    #endif
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<ll,ll> pll;
    typedef pair<double,double> pdd;
    typedef long double ld;
    #define F first
    #define S second
    #define ALL(x)  (x).begin(),(x).end()
    #define SZ(x)   (ll)x.size()
    #define pb push_back
    #define eb emplace_back
    #define stp setprecision(30)<<fixed
    #define mdel(m, x) do{if(--m[x] == 0)m.erase(x);}while(0)
    #define mexi(m, x) (m.find(x) != m.end())
    #define mmin(m) (m.begin()->F)
    #define mmax(m) (m.rbegin()->F)
    #define LS(x) ((x<<1)+1)
    #define RS(x) ((x+1)<<1)
    const int NF = 0x3f3f3f3f;
    const ll INF = 0x3f3f3f3f3f3f3f3f;
    const ll MO7 = 1e9 + 7;
    const ll MO9 = 1e9 + 9;
    const ll MO87 = 1e9 + 87;
    const ll MO93 = 1e9 + 93;
    const ll MO53 = 998244353;
    const ld PI = 3.14159265358979323846264338327950288;
    const ld eps = 1e-7;
//}
const ll MAX = 5e3 + 6, Mlg = __lg(MAX) + 2;
int n, m;
string s1, s2;
int dp[MAX][MAX];
int que(int x, int y) {
    if(dp[x][y] != -1)  return dp[x][y];
    int ma = 2;
    for(int i = x + 1; i < min(n, x + 4); ++ i) {
        for(int j = y + 1; j < min(m, y + 4); ++ j ) {
            if(s1[i] == s2[j]) {
                ma = max(ma, que(i, j) + 4 - (i - x) - (j - y) );
            }
        }
    }
    return dp[x][y] = ma;
}
int main() {
    IOS;
    cin >> n >> m;
    cin >> s1 >> s2;
    memset(dp, -1, sizeof dp);
    int ma = 0;
    for(int i = 0; i < n; ++ i) {
        for(int j = 0; j < m; ++ j) {
            if(s1[i] == s2[j])
                ma = max(ma, que(i, j));
        }
    }
    cout << ma << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<ll,ll>
#define piii pair<pii, ll>
#define pb push_back
#define fs first
#define sc second
#define ppb pop_back
//#define ONLINE_JUDGE
#define endl "\n"
#define pow2(i) (1<<(i))
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
#define fifo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1e9+7;
const int inf = 1e9+1;

char a[5001],b[5001]; int dp[5001][5001]; int n,m;
void solve()
{
	cin>>n>>m;

	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			dp[i][j]=0;

	cin>>a>>b;
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(a[i-1]==b[j-1])
			{
				dp[i][j] = max(dp[i][j],dp[i-1][j-1]+2);
			}
			else
			{
				dp[i][j] = max(dp[i][j],max(dp[i-1][j],dp[i][j-1])-1);
			}
			ans = max(ans,dp[i][j]);
		}

	d1(ans);
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif

	fifo
	ll t=1;
	//cin>>t;
	for(ll tc=1;tc<=t;++tc)
	{
		solve();
	}
}


/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 5010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, dp[MAXN][MAXN];
string s, t;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;
    FOR(i,1,n)
        FOR(j,1,m)
            if (s[i] == t[j]) {
                dp[i][j] = max(2, dp[i-1][j-1] + 2);
            }
            else {
                dp[i][j] = max(0, max(dp[i-1][j] - 1, dp[i][j-1] - 1));
            }
    int res = 0;
    FOR(i,1,n)
        FOR(j,1,m) res = max(res, dp[i][j]);
    cout << res;
    return 0;
}


/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 5010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, dp[MAXN][MAXN];
string s, t;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;
    FOR(i,1,n)
        FOR(j,1,m)
            if (s[i] == t[j]) {
                dp[i][j] = 2;
                FOR(u,max(1,i-3),max(1,i-1))
                    FOR(v,max(1,j-3),max(1,j-1)) {
                        if (u >= i || v >= j) continue;
                        int sum = i - u + j - v;
                        if (s[u] == t[v]) dp[i][j] = max(dp[i][j], dp[u][v] + 4 - sum);
                        // if (i == 4 && j == 2) {
                        //     cout << sum << ' ' << u << ' ' << v << ' ' << s[u] << ' ' << t[v] << ' ' << dp[u][v] << endl;
                        // }
                    }
            }
            else dp[i][j] = 0;
    // FOR(i,1,n) {
    //     FOR(j,1,m) cout << dp[i][j] << ' ';
    //     cout << endl;
    // }
    int res = 0;
    FOR(i,1,n)
        FOR(j,1,m) res = max(res, dp[i][j]);
    cout << res;
    return 0;
}


/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 5010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, dp[MAXN][MAXN];
string s, t;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;
    FOR(i,1,n)
        FOR(j,1,m)
            if (s[i] == t[j]) {
                dp[i][j] = 2;
                FOR(u,max(1,i-2),max(1,i-1))
                    FOR(v,max(1,j-2),max(1,j-1)) {
                        if (u >= i || v >= j) continue;
                        int sum = i - u + j - v;
                        if (s[u] == t[v]) dp[i][j] = max(dp[i][j], dp[u][v] + 4 - sum);
                        // if (i == 4 && j == 2) {
                        //     cout << sum << ' ' << u << ' ' << v << ' ' << s[u] << ' ' << t[v] << ' ' << dp[u][v] << endl;
                        // }
                    }
            }
            else dp[i][j] = 0;
    // FOR(i,1,n) {
    //     FOR(j,1,m) cout << dp[i][j] << ' ';
    //     cout << endl;
    // }
    int res = 0;
    FOR(i,1,n)
        FOR(j,1,m) res = max(res, dp[i][j]);
    cout << res;
    return 0;
}


/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 5010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, dp[MAXN][MAXN];
string s, t;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    cin >> s >> t;
    s = " " + s;
    t = " " + t;
    FOR(i,1,n)
        FOR(j,1,m)
            if (s[i] == t[j]) {
                dp[i][j] = 2;
                FOR(u,max(1,i-10),max(1,i-1))
                    FOR(v,max(1,j-10),max(1,j-1)) {
                        if (u >= i || v >= j) continue;
                        int sum = i - u + j - v;
                        if (s[u] == t[v]) dp[i][j] = max(dp[i][j], dp[u][v] + 4 - sum);
                        // if (i == 4 && j == 2) {
                        //     cout << sum << ' ' << u << ' ' << v << ' ' << s[u] << ' ' << t[v] << ' ' << dp[u][v] << endl;
                        // }
                    }
            }
            else dp[i][j] = 0;
    // FOR(i,1,n) {
    //     FOR(j,1,m) cout << dp[i][j] << ' ';
    //     cout << endl;
    // }
    int res = 0;
    FOR(i,1,n)
        FOR(j,1,m) res = max(res, dp[i][j]);
    cout << res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 2e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M >> a >> b;
	if (N > M) swap(a, b);

	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
			dp[i][j] = max(dp[i][j], max(dp[i][j - 1], dp[i - 1][j]) - 1);
		}
	}

	int ans = 0;
	FOR(i, 1, N + 1) FOR(j, 1, M + 1) ans = max(ans, dp[i][j]);
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M >> a >> b;
	if (N > M) swap(a, b);

	int ans = 0;
	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
			if (a[i - 1] == b[j - 1]) {
				dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
				dp[i][j] = max(dp[i][j], 2);
			}
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M >> a >> b;
	if (N > M) swap(a, b);

	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
			else dp[i][j] = max(dp[i][j], max(dp[i][j - 1], dp[i - 1][j]) - 1);
		}
	}

	int ans = 0;
	FOR(i, 1, N + 1) FOR(j, 1, M + 1) ans = max(ans, dp[i][j]);
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
char a[MX], b[MX];

int main() {
	cin >> N >> M;
	FOR(i, 0, N) cin >> a[i];
	FOR(i, 0, M) cin >> b[i];

	int ans = 0;
	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			dp[i][j] = max(dp[i - 1][j] - 1, dp[i][j - 1] - 1);
			if (a[i - 1] == b[j - 1]) {
				dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
				dp[i][j] = max(dp[i][j], 2);
			}
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M >> a >> b;
	if (N > M) swap(a, b);

	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
			dp[i][j] = max(dp[i][j], max(dp[i][j - 1], dp[i - 1][j]) - 1);
		}
	}

	int ans = 0;
	FOR(i, 1, N + 1) FOR(j, 1, M + 1) ans = max(ans, dp[i][j]);
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M >> a >> b;
	if (N > M) swap(a, b);

	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
			if (a[i - 1] == b[j - 1]) {
				dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
				dp[i][j] = max(dp[i][j], 2);
			}
		}
	}

	int ans = 0;
	FOR(i, 1, N + 1) FOR(j, 1, M + 1) ans = max(ans, dp[i][j]);
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M;
	cin >> a >> b;

	int ans = 0;
	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
			if (a[i - 1] == b[j - 1]) {
				dp[i][j] = max(dp[i - 1][j - 1] + 2, dp[i][j]);
				dp[i][j] = max(dp[i][j], 2);
			}
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 5e3 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define re(x) cin >> x
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define len(x) (int)x.length()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit);
		// throws exception when do smth illegal2
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N, M;
int dp[MX][MX];
string a, b;

int main() {
	cin >> N >> M >> a >> b;
	if (N > M) swap(a, b);

	FOR(i, 1, N + 1) {
		FOR(j, 1, M + 1) {
			if (a[i - 1] == b[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 2);
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;
		}
	}

	int ans = 0;
	FOR(i, 1, N + 1) FOR(j, 1, M + 1) ans = max(ans, dp[i][j]);
	cout << ans << "\n";
}


#include <iostream>
#include<string>
using namespace std;
long int max(long int a,long int b){
	return a>b?a:b;
}
int main(){
	int n,m;
	cin >> n >> m;
	string a,b;
	cin >> a;
	cin >> b;
	long int dp[n+1][m+1][2];
	for(int i=0;i<n+1;i++)for(int j=0;j<m+1;j++)for(int k=0;k<2;k++)dp[i][j][k]=0;
	for(int i=n-1;i>=0;i--){
		for(int j=m-1;j>=0;j--){

			long ans=0;
			ans=max(ans,dp[i+1][j+1][1]+(a[i]==b[j]?2:-2));
            ans=max(ans,dp[i+1][j][1]-1);
            ans=max(ans,dp[i][j+1][1]-1);
            dp[i][j][1]=ans;

            ans=0;
            if(a[i]==b[j])ans=max(ans,dp[i+1][j+1][1]+2);
            ans=max(ans,dp[i+1][j][0]);
            ans=max(ans,dp[i][j+1][0]);
            dp[i][j][0]=ans;

		}
	}
	cout<<dp[0][0][0];
	return 0;
}


#include <iostream>
#include<string>
using namespace std;
long long max(long long a,long long b){
	return a>b?a:b;
}
int main(){
	int n,m;
	cin >> n >> m;
	string a,b;
	cin >> a;
	cin >> b;
	long long dp[n+1][m+1][2];
	for(int i=0;i<n+1;i++)for(int j=0;j<m+1;j++)for(int k=0;k<2;k++)dp[i][j][k]=0;
	for(int i=n-1;i>=0;i--){
		for(int j=m-1;j>=0;j--){

			long ans=0;
			ans=max(ans,dp[i+1][j+1][1]+(a[i]==b[j]?2:-2));
            ans=max(ans,dp[i+1][j][1]-1);
            ans=max(ans,dp[i][j+1][1]-1);
            dp[i][j][1]=ans;

            ans=0;
            if(a[i]==b[j])ans=max(ans,dp[i+1][j+1][1]+2);
            ans=max(ans,dp[i+1][j][0]);
            ans=max(ans,dp[i][j+1][0]);
            dp[i][j][0]=ans;

		}
	}
	cout<<dp[0][0][0];
	return 0;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

const int N = 5050;
int n, m;
int dp[N][N];
char a[N], b[N];

int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	scanf("%d%d", &n, &m);
	scanf("%s %s", a, b);
	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 (a[i] == b[j])
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 2);
		}
	int ans = 0;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= m; j++)
			ans = max(ans, dp[i][j]);
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

#define rep(i,a,b) for(ll i = a; i<b;i++)
#define per(i,a,b) for(ll i = a; i>=b; i--)
#define inf LLONG_MAX
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto &a: x)
#define mp(x,y) make_pair(x,y)

int main(){
  ios::sync_with_stdio(0);
  cin.tie(NULL); cout.tie(NULL);
  cout << setprecision(15) << fixed;
  ll n,m; cin >> n >> m;
  vector<vi> dp;
  vi _; _.assign(n+1,0);
  dp.assign(m+1,_);
  string a,b; cin >> a >> b;
  ll ma = 0;
  per(i,m-1,0) per(j,n-1,0){
    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], dp[i][j+1] - 1);
    dp[i][j] = max(dp[i][j], dp[i+1][j] - 1);
    ma = max(dp[i][j],ma);
  }
  cout << ma << endl;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;

#define rep(i,a,b) for(ll i = a; i<b;i++)
#define per(i,a,b) for(ll i = a; i>=b; i--)
#define inf LLONG_MAX
#define all(x) x.begin(),x.end()
#define sz(x) (ll)(x).size()
#define trav(a,x) for(auto &a: x)
#define mp(x,y) make_pair(x,y)

int main(){
  ios::sync_with_stdio(0);
  cin.tie(NULL); cout.tie(NULL);
  cout << setprecision(15) << fixed;
  ll n,m; cin >> m >> n;
  vector<vi> dp;
  vi _; _.assign(n+1,0);
  dp.assign(m+1,_);
  string a,b; cin >> a >> b;
  ll ma = 0;
  per(i,m-1,0) per(j,n-1,0){
    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], dp[i][j+1] - 1);
    dp[i][j] = max(dp[i][j], dp[i+1][j] - 1);
    ma = max(dp[i][j],ma);
  }
  cout << ma << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int N=5005;
int f[N][N];
string s,t;
int res,i,j,n,m;
int main()
{
    cin>>n>>m;
    cin>>s;
    cin>>t;
    s=' '+s;
    t=' '+t;
    res=0;
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
    {
        f[i][j]=max(f[i-1][j],f[i][j-1])-1;
        if (s[i]==t[j])
            f[i][j]=max(f[i][j],f[i-1][j-1]+2);
        res=max(res,f[i][j]);
    }

    cout<<res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=5005;
int f[N][N];
string s,t;
int res,i,j,n,m;
int main()
{
    cin>>n>>m;
    cin>>s;
    cin>>t;
    s=' '+s;
    t=' '+t;
    res=0;
    for (i=1;i<=n;i++)
        for (j=1;j<=m;j++)
    {
        f[i][j]=max(0,max(f[i-1][j],f[i][j-1])-1);
        if (s[i]==t[j])
            f[i][j]=max(f[i][j],f[i-1][j-1]+2);
        res=max(res,f[i][j]);
    }

    cout<<res;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

struct ttt{
    short i, j, len;
    int score() const { return 4*len - i - j;}
    bool operator < (const ttt& o) const {
        int x = score();
        int y = o.score();
        return x < y;
    }
    ttt(){
        i = j = len = 0;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;

    vector<vector<ttt>> dp(n+1);
    ttt sol = {};
    FOR(i, n+1){
        dp[i].resize(m+1);
        FOR(j, m+1){
            if (i){
                auto tp = dp[i-1][j];
                tp.i++;
                umax(dp[i][j], tp);
            }
            if (j){
                auto tp = dp[i][j-1];
                tp.j++;
                umax(dp[i][j], tp);
            }
            if (i && j){
                auto tp = dp[i-1][j-1];
                int dl = a[i-1] == b[j-1];
                if (tp.len == 0 && dl) {
                    tp.i = 1;
                    tp.j = 1;
                }
                else{
                    tp.i++;
                    tp.j++;
                }
                tp.len += dl;
                umax(dp[i][j], tp);
            }
            umax(sol, dp[i][j]);
        }
        if (i>0) dp[i-1].clear();
    }
    cout << sol.score() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

struct ttt{
    short i, j, len;
    int score() const { return 4*len - i - j;}
    bool operator < (const ttt& o) const {
        int x = score();
        int y = o.score();
        return x < y;
    }
    ttt(){
        i = j = len = 0;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;

    vector<vector<ttt>> dp(n+1);
    ttt sol = {};
    FOR(i, n+1){
        dp[i].resize(m+1);
        FOR(j, m+1){
            if (i){
                auto tp = dp[i-1][j];
                tp.i++;
                umax(dp[i][j], tp);
            }
            if (j){
                auto tp = dp[i][j-1];
                tp.j++;
                umax(dp[i][j], tp);
            }
            if (i && j){
                auto tp = dp[i-1][j-1];
                int dl = a[i-1] == b[j-1];
                if (tp.len == 0 && dl) {
                    tp.i = 1;
                    tp.j = 1;
                }
                else{
                    tp.i++;
                    tp.j++;
                }
                tp.len += dl;
                umax(dp[i][j], tp);
            }
            umax(sol, dp[i][j]);
        }
        if (i>0) dp[i-1] = vector<ttt>();
    }
    cout << sol.score() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

struct ttt{
    int i0, j0, i, j, len;
    int score() const { return 4*len - (i - i0 + 1) - (j - j0 + 1);}
    bool operator < (const ttt& o) const {
        int x = score();
        int y = o.score();
        return x < y;
    }
    ttt(){
        i = j = len = 0;
        i0 = j0 = 1;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;

    vector<vector<ttt>> dp;
    init(dp, ttt(), n+1, m+1);
    ttt sol = {};
    FOR(i, n+1){
        FOR(j, m+1){
            if (i){
                auto tp = dp[i-1][j];
                tp.i = i;
                umax(dp[i][j], tp);
            }
            if (j){
                auto tp = dp[i][j-1];
                tp.j = j;
                umax(dp[i][j], tp);
            }
            if (i && j){
                auto tp = dp[i-1][j-1];
                tp.i = i;
                tp.j = j;
                tp.len += a[i-1] == b[j-1];
                if (tp.len == 1) {
                    tp.i0 = i;
                    tp.j0 = j;
                }
                umax(dp[i][j], tp);
            }
            umax(sol, dp[i][j]);
        }
    }
    cout << sol.score() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

struct ttt{
    short i, j, len;
    int score() const { return 4*len - i - j;}
    bool operator < (const ttt& o) const {
        int x = score();
        int y = o.score();
        return x < y;
    }
    ttt(){
        i = j = len = 0;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;

    vector<vector<ttt>> dp;
    init(dp, ttt(), n+1, m+1);
    ttt sol = {};
    FOR(i, n+1){
        FOR(j, m+1){
            if (i){
                auto tp = dp[i-1][j];
                tp.i++;
                umax(dp[i][j], tp);
            }
            if (j){
                auto tp = dp[i][j-1];
                tp.j++;
                umax(dp[i][j], tp);
            }
            if (i && j){
                auto tp = dp[i-1][j-1];
                int dl = a[i-1] == b[j-1];
                if (tp.len == 0 && dl) {
                    tp.i = 1;
                    tp.j = 1;
                }
                else{
                    tp.i++;
                    tp.j++;
                }
                tp.len += dl;
                umax(dp[i][j], tp);
            }
            umax(sol, dp[i][j]);
        }
    }
    cout << sol.score() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); }
template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n);  for(auto& a : v) init(a, x, m...); }

struct ttt{
    int i0, j0, i1, j1, len;
    int score() const { return 4*len - (i1 - i0 + 1) - (j1 - j0 + 1);}
    bool operator < (const ttt& o) const {
        int x = score();
        int y = o.score();
        return x < y;
    }
    ttt(){
        i1 = j1 = len = 0;
        i0 = j0 = 1;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n, m;
    cin >> n >> m;
    string a, b;
    cin >> a >> b;

    vector<vector<ttt>> dp;
    init(dp, ttt(), n+1, m+1);
    ttt sol = {};
    FOR(i, n+1){
        FOR(j, m+1){
            if (i){
                auto tp = dp[i-1][j];
                tp.i1 = i;
                umax(dp[i][j], tp);
            }
            if (j){
                auto tp = dp[i][j-1];
                tp.j1 = j;
                umax(dp[i][j], tp);
            }
            if (i && j){
                auto tp = dp[i-1][j-1];
                tp.i1 = i;
                tp.j1 = j;
                int dl = a[i-1] == b[j-1];
                if (tp.len == 0 && dl) {
                    tp.i0 = i;
                    tp.j0 = j;
                }
                tp.len += dl;
                umax(dp[i][j], tp);
            }
            umax(sol, dp[i][j]);
        }
    }
    cout << sol.score() << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}


#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 2000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

string a,b;
ll n,m;
#define N 5005
ll dp[N][N];

ll get(ll i, ll j)
{
    if(i == n || j == m)
        return 0;
    if(dp[i][j] != -inf)
        return dp[i][j];
    ll ans = -2;
    if(a[i] == b[j])
        ans+=4;
    ans+=max(0, get(i+1,j+1));
    ans = max(ans, get(i,j+1) - 1);
    ans = max(ans, get(i+1,j) - 1);
    return dp[i][j] = ans;
}

int main()
{
  FAST/**/

   cin>>n>>m;
   cin>>a>>b;

   rep(n)
        repi(j,m)
            dp[i][j] = -inf;
   ll ans = -2;
   rep(n)
        repi(j,m)
            ans = max(ans, get(i,j));
   ans = max(ans, 0);
   cout<<ans;

  return 0;
}