#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e2 + 5;
const long long P = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  long long ans = 1e18;
  for (int i = 0; i < n; i++) {
    long long now = -1e18;
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      for (int k = 0; k < m; k++) now = max(now, 1ll * a[j] * b[k]);
    }
    ans = min(ans, now);
  }
  cout << ans << endl;
}
