#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<long long> a;
vector<long long> b;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long ans = numeric_limits<long long>::min();
  for (int forbidden = 0; forbidden < n; ++forbidden) {
    long long tmp = numeric_limits<long long>::min();
    for (int chosen_a = 0; chosen_a < n; ++chosen_a)
      for (int chosen_b = 0; chosen_b < m; ++chosen_b)
        if (chosen_a != forbidden) tmp = max(tmp, a[chosen_a] * b[chosen_b]);
    if (ans == numeric_limits<long long>::min())
      ans = tmp;
    else
      ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}
