#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  vector<pair<long long, long long> > prod;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) prod.push_back({a[i] * b[j], a[i]});
  }
  sort(prod.begin(), prod.end());
  long long x = prod[prod.size() - 1].second;
  vector<long long> prod1;
  bool done = false;
  for (long long i = 0; i < n; i++) {
    if (a[i] == x and !done) {
      done = true;
      continue;
    }
    for (long long j = 0; j < m; j++) prod1.push_back(a[i] * b[j]);
  }
  sort(prod1.begin(), prod1.end());
  cout << prod1[prod1.size() - 1] << "\n";
}
