#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a1, b1;
  cin >> a1 >> b1;
  vector<long long> v, a, b, v2;
  for (int i = 0; i < a1; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < b1; i++) {
    int x;
    cin >> x;
    b.push_back(x);
  }
  for (int i = 0; i < a1; i++) {
    for (int j = 0; j < b1; j++) {
      long long x = a[i] * b[j];
      v.push_back(x);
    }
    sort(v.begin(), v.end());
    v2.push_back(v[v.size() - 1]);
    v.clear();
  }
  sort(v2.begin(), v2.end());
  cout << v2[v2.size() - 2] << endl;
  return 0;
}
