#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long arr[55];
long long arr1[55];
int32_t main() {
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &arr[i]);
  }
  for (long long i = 1; i <= m; i++) {
    scanf("%lld", &arr1[i]);
  }
  long long mx = -1000000000000000009;
  long long p;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      long long t = arr1[i] * arr[j];
      if (t > mx) {
        mx = t;
        p = j;
      }
    }
  }
  arr[p] = 1000000009;
  mx = -1000000000000000009;
  for (long long i = 1; i <= m; i++) {
    for (long long j = 1; j <= n; j++) {
      if (arr[j] != 1000000009) {
        long long t = arr1[i] * arr[j];
        if (t > mx) {
          mx = t;
        }
      }
    }
  }
  printf("%lld", mx), printf("\n");
  return 0;
}
