#include <bits/stdc++.h>
using namespace std;
int a[55], b[55];
bool hide[55];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", &b[i]);
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  long long ans = 2e18;
  for (int i = 1; i <= n; i++) {
    hide[i] = 1;
    long long tmp = -2e18;
    long long aa = a[1];
    long long bb = b[1];
    if (hide[1]) aa = a[2];
    tmp = max(tmp, aa * bb);
    bb = b[m];
    tmp = max(tmp, aa * bb);
    aa = a[n];
    bb = b[m];
    if (hide[n]) aa = a[n - 1];
    tmp = max(tmp, aa * bb);
    bb = b[1];
    tmp = max(tmp, aa * bb);
    ans = min(ans, tmp);
    hide[i] = 0;
  }
  printf("%lld\n", ans);
}
