#include <bits/stdc++.h>
using namespace std;
const int N = 55;
long long a[N], b[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
  for (int i = 1; i <= m; i++) scanf("%I64d", &b[i]);
  long long ans = 2e18;
  for (int i = 1; i <= n; i++) {
    long long res = -2e18;
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      for (int k = 1; k <= m; k++) {
        res = max(res, a[j] * b[k]);
      }
    }
    ans = min(ans, res);
  }
  printf("%I64d\n", ans);
  return 0;
}
