#include <bits/stdc++.h>
using namespace std;
char st[2010];
long long mat[2010][2010], sumR[2010][2010], sumC[2010][2010];
const long long inf = (1LL << 60) - 1;
const long long mxn = 1e5;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<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];
  long long res = inf;
  for (long long i = 0; i < n; i++) {
    long long now = -inf;
    for (long long j = 0; j < n; j++) {
      if (j != i) {
        for (long long k = 0; k < m; k++) now = max(now, a[j] * b[k]);
      }
    }
    res = min(res, now);
  }
  cout << res << "\n";
}
int main() {
  solve();
  return 0;
}
