#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> a(n), b(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
  }
  ll res = LLONG_MAX;
  for (int i = 0; i < n; i++) {
    ll val = LLONG_MIN;
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < n; k++)
        if (k != i) {
          val = max(val, a[k] * b[j]);
        }
    }
    res = min(res, val);
  }
  cout << res << endl;
  return 0;
}
