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