#include <bits/stdc++.h>
using namespace std;
const int64_t inf = 1e15;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int64_t> a(n), b(m);
for (auto &i : a) {
cin >> i;
}
for (auto &i : b) {
cin >> i;
}
vector<int> ig, jg;
auto populate = [&](vector<int> &ig, int n, vector<int64_t> &a) {
for (int i = 0; i < n; ++i) {
while (ig.size() >= 2 && a[ig[ig.size() - 2]] <= a[ig[ig.size() - 1]] && a[ig[ig.size() - 1]] >= a[i]) {
ig.pop_back();
}
ig.push_back(i);
}
ig.push_back(0);
ig.push_back(n - 1);
ig.push_back(n);
sort(ig.begin(), ig.end());
ig.erase(unique(ig.begin(), ig.end()), ig.end());
};
populate(ig, n, a);
populate(jg, m, b);
vector dp(ig.size(), vector<int64_t>(jg.size()));
for (int i = ig.size() - 1; i >= 0; --i) {
for (int j = jg.size() - 1; j >= 0; --j) {
if (ig[i] == n || jg[j] == m) {
dp[i][j] = inf;
continue;
}
if (ig[i] == n - 1 && jg[j] == m - 1) {
dp[i][j] = 0;
continue;
}
dp[i][j] = min(dp[i][j + 1] + a[ig[i]] * (jg[j + 1] - jg[j]), dp[i + 1][j] + b[jg[j]] * (ig[i + 1] - ig[i]));
}
}
cout << dp[0][0] << '\n';
}