#include <bits/extc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
void prev_greater(vector<int>& r, const vector<int>& a) {
stack<int> s;
for (int i = 0; i < a.size(); i++) {
while (!s.empty() && a[s.top()] <= a[i]) {
s.pop();
}
r[i] = s.empty() ? -1 : s.top();
s.push(i);
}
}
void prev_less(vector<int>& r, const vector<int>& a) {
stack<int> s;
for (int i = 0; i < a.size(); i++) {
while (!s.empty() && a[s.top()] >= a[i]) {
s.pop();
}
r[i] = s.empty() ? -1 : s.top();
s.push(i);
}
}
void next_greater(vector<int>& r, const vector<int>& a) {
stack<int> s;
for (int i = a.size() - 1; i >= 0; i--) {
while (!s.empty() && a[s.top()] <= a[i]) {
s.pop();
}
r[i] = s.empty() ? a.size() : s.top();
s.push(i);
}
}
void next_less(vector<int>& r, const vector<int>& a) {
stack<int> s;
for (int i = a.size() - 1; i >= 0; i--) {
while (!s.empty() && a[s.top()] >= a[i]) {
s.pop();
}
r[i] = s.empty() ? a.size() : s.top();
s.push(i);
}
}
signed main() {
#ifdef CB
ifstream fin("be1.txt");
cin.rdbuf(fin.rdbuf());
ofstream fout("ki.txt");
#endif
int A, B;
cin >> A >> B;
vector<int> a(A), b(B);
for (int i = 0; i < A; i++) {
cin >> a[i];
}
for (int i = 0; i < B; i++) {
cin >> b[i];
}
vector<int> pa(A), na(A);
vector<int> pb(B), nb(B);
prev_less(pa, a);
next_less(na, a);
prev_greater(pb, b);
next_greater(nb, b);
vector<int> da(A), db(B);
for (int i = 0; i < A; i++) {
da[i] = na[i] - pa[i] - 1;
}
for (int i = 0; i < B; i++) {
db[i] = nb[i] - pb[i] - 1;
}
vector<int> ib(B);
iota(ib.begin(), ib.end(), 0);
sort(ib.begin(), ib.end(), [&](int i, int j) { return b[i] < b[j]; });
vector<int> mb(B + 1);
for (int i = 0; i < B; i++) {
mb[i + 1] = max(mb[i], db[ib[i]]);
}
sort(b.begin(), b.end());
int ans = 0;
for (int i = 0; i < A; i++) {
int j = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
ans = max(ans, da[i] * mb[j]);
}
cout << ans << endl;
return 0;
}