#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 100'001;
int a[MAXN], b[MAXN], bef[MAXN], aft[MAXN], par[MAXN], siz[MAXN], biggest = 1;
int holvan(int u) {
return par[u] == u ? u : par[u] = holvan(par[u]);
}
void unio(int u, int v) {
u = holvan(u); v = holvan(v);
if (u == v) return;
siz[u] += siz[v];
biggest = max(biggest, siz[u]);
par[v] = u;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, m; cin >> n >> m;
iota(par, par+MAXN, 0);
fill(siz, siz+MAXN, 1);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
vector<int> indices(n);
iota(indices.begin(), indices.end(), 1);
sort(indices.begin(), indices.end(), [&](int i, int j){
return a[i] < a[j];
});
stack<int> st;
for (int i = 1; i <= n; i++) {
while (!st.empty() && a[st.top()] >= a[i]) st.pop();
bef[i] = st.empty() ? 0 : st.top();
st.push(i);
}
st = stack<int>();
for (int i = n; i >= 1; i--) {
while (!st.empty() && a[st.top()] >= a[i]) st.pop();
aft[i] = st.empty() ? n+1 : st.top();
st.push(i);
}
int mine = *min_element(b+1, b+m+1);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for (int i = 1; i < m; i++) {
int w = max(b[i], b[i+1]);
pq.push({w, i});
}
ll ans = 0;
for (int i : indices) {
if (a[i] < mine) continue;
while (!pq.empty() && pq.top().first <= a[i]) {
unio(pq.top().second, pq.top().second+1);
pq.pop();
}
ll len = (aft[i] - bef[i] - 1);
ans = max(ans, len * biggest);
}
cout << ans << "\n";
return 0;
}