#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, i, j, k;
  cin >> n >> m;
  long long a[n], b[m], m1;
  vector<long long> v;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (j = 0; j < n; ++j) {
    m1 = LLONG_MIN;
    for (k = 0; k < m; ++k) {
      m1 = max(m1, a[j] * b[k]);
    }
    v.push_back(m1);
  }
  sort(v.begin(), v.end());
  cout << v[v.size() - 2];
  return 0;
}
