#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[51];
  int b[51];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  vector<long long> vs;
  for (int i = 0; i < n; ++i) {
    long long v = a[i];
    long long c = -1e18;
    for (int j = 0; j < m; ++j) {
      long long p = v * 1LL * b[j];
      c = max(c, p);
    }
    vs.push_back(c);
  }
  sort(vs.begin(), vs.end());
  cout << vs[n - 2];
}
