#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 60) - 1;
int main() {
  int n, m;
  cin >> n >> m;
  long long A[n], B[m];
  int i;
  for (i = 0; i < n; i++) cin >> A[i];
  for (i = 0; i < m; i++) cin >> B[i];
  long long res = INF;
  for (i = 0; i < n; i++) {
    long long cur = -INF;
    for (int j = 0; j < n; j++)
      if (j != i)
        for (int k = 0; k < m; k++) cur = max(cur, A[j] * B[k]);
    res = min(cur, res);
  }
  cout << res;
  return 0;
}
