#include <bits/stdc++.h>
using namespace std;
int cmpfunc(const void *a, const void *b) { return (*(int *)a) - (*(int *)b); }
int main() {
  long long int n, m, arr1[100], arr2[100], i, j, arr3[100000], temp, max;
  scanf("%lld %lld", &n, &m);
  for (i = 0; i < n; i++) scanf("%lld", &arr1[i]);
  for (i = 0; i < m; i++) scanf("%lld", &arr2[i]);
  sort(arr1, arr1 + n);
  sort(arr2, arr2 + m);
  for (i = 0; i < n; i++) {
    max = -1000000000000000003;
    for (j = 0; j < m; j++) {
      temp = arr1[i] * arr2[j];
      if (max < temp) max = temp;
    }
    arr3[i] = max;
  }
  sort(arr3, arr3 + n);
  printf("%lld", arr3[n - 2]);
  return 0;
}
