#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
struct upd {
int val, ab, ind;
};
struct node {
int lft, mid, rgt;
ll pref, lng, suff;
};
int n, m;
ll ans = 0;
vector <upd> U;
vector <node> sgt1(4e5);
vector <node> sgt2(4e5);
bool smaller(upd a, upd b) {
if (a.val < b.val) return true;
if (a.val > b.val) return false;
return (a.ab > b.ab ? true : false);
}
void build1(int x, int l, int r) {
node& N = sgt1[x];
N.lft = l;
N.mid = (l + r) / 2;
N.rgt = r;
N.pref = N.lng = N.suff = r - l;
if (r - l == 1) return;
build1(2 * x, l, N.mid);
build1(2 * x + 1, N.mid, r);
}
void build2(int x, int l, int r) {
node& N = sgt2[x];
N.lft = l;
N.rgt = r;
N.mid = (l + r) / 2;
N.pref = N.lng = N.suff = 0;
if (r - l == 1) return;
build2(2 * x, l, N.mid);
build2(2 * x + 1, N.mid, r);
}
void update1(int x, int i) {
node& N = sgt1[x];
if (N.rgt - N.lft == 1) {
N.pref = N.lng = N.suff = 0;
return;
}
(i < N.mid ? update1(2 * x, i) : update1(2 * x + 1, i));
node& N1 = sgt1[2 * x];
node& N2 = sgt1[2 * x + 1];
N.pref = (N1.pref < N1.rgt - N1.lft ? N1.pref : N1.pref + N2.pref);
N.lng = max(N1.suff + N2.pref, max(N1.lng, N2.lng));
N.suff = (N2.suff < N2.rgt - N2.lft ? N2.suff : N2.suff + N1.suff);
}
void update2(int x, int i) {
node& N = sgt2[x];
if (N.rgt - N.lft == 1) {
N.pref = N.lng = N.suff = 1;
return;
}
(i < N.mid ? update2(2 * x, i) : update2(2 * x + 1, i));
node& N1 = sgt2[2 * x];
node& N2 = sgt2[2 * x + 1];
N.pref = (N1.pref < N1.rgt - N1.lft ? N1.pref : N1.pref + N2.pref);
N.lng = max(N1.suff + N2.pref, max(N1.lng, N2.lng));
N.suff = (N2.suff < N2.rgt - N2.lft ? N2.suff : N2.suff + N1.suff);
}
int main()
{
cin >> n >> m;
U.resize(n + m);
for (int i = 0; i < n; i++) {
cin >> U[i].val;
U[i].ab = 1;
U[i].ind = i;
}
for (int i = n; i < n + m; i++) {
cin >> U[i].val;
U[i].ab = 2;
U[i].ind = i - n;
}
sort(U.begin(), U.end(), smaller);
build1(1, 0, n);
build2(1, 0, m);
for (upd& u : U) {
(u.ab == 1 ? update1(1, u.ind) : update2(1, u.ind));
ans = max(ans, sgt1[1].lng * sgt2[1].lng);
//cout << u.ab << " " << u.val << " " << u.ind << " " << sgt1[1].lng << " " << sgt2[1].lng << endl;
}
cout << ans;
}