#include <bits/stdc++.h>
using namespace std;
vector<long long> a, b, res;
int main() {
  long long m, n;
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  res.resize(n);
  for (long long i = 0; i < (n); ++i) {
    cin >> a[i];
  }
  for (long long i = 0; i < (m); ++i) {
    cin >> b[i];
  }
  for (long long i = 0; i < (n); ++i) {
    long long curr_max = a[i] * b[0];
    for (long long j = 0; j < (m); ++j) {
      long long curr = a[i] * b[j];
      if (curr > curr_max) curr_max = curr;
    }
    res[i] = curr_max;
  }
  sort(res.begin(), res.end());
  cout << res[n - 2];
  return 0;
}
