#include <bits/stdc++.h>
long long int n, m, a[51], b[51], mar[51], result[51];
bool mycom(long long x, long long y) { return (x > y); }
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &b[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      mar[j] = a[i] * b[j];
    }
    std::sort(mar, mar + m, mycom);
    result[i] = mar[0];
  }
  std::sort(result, result + n, mycom);
  printf("%I64d\n", result[1]);
  return 0;
}
