#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0), cout.precision(15);
  int n, m;
  cin >> n >> m;
  vector<ll> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<ll> c1, c2;
  for (int i = 0; i < n - 1; i++) {
    c1.push_back(a[i] * b[0]);
    c1.push_back(a[i] * b[m - 1]);
  }
  for (int i = 1; i < n; i++) {
    c2.push_back(a[i] * b[0]);
    c2.push_back(a[i] * b[m - 1]);
  }
  sort(c1.begin(), c1.end());
  sort(c2.begin(), c2.end());
  cout << min(c1.back(), c2.back()) << endl;
  return 0;
}
