#include <bits/stdc++.h>
int main(void) {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    long long a[n], b[m];
    long long max_product[51];
    for (int i = 0; i < 51; i++) {
      max_product[i] = LONG_LONG_MIN;
    }
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    for (int i = 0; i < m; i++) {
      scanf("%lld", &b[i]);
    }
    for (int i = 0; i < n; i++) {
      for (int k = 0; k < n; k++) {
        if (k == i) {
          continue;
        }
        for (int t = 0; t < m; t++) {
          if (a[k] * b[t] > max_product[i]) {
            max_product[i] = a[k] * b[t];
          }
        }
      }
    }
    long long max_b_product = max_product[0];
    std::sort(max_product, max_product + n);
    printf("%lld\n", max_product[0]);
  }
  return 0;
}
