#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x7fffffff;
const long long INFF = 0x7fffffffffffffff;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mxx = 1333331;
long long a[55], b[55], c[55];
int main() {
  int n, m;
  long long n_max = LLONG_MIN, n_second_max = LLONG_MIN, m_max = LLONG_MIN;
  long long num;
  for (int i = 0; i < 55; i++) {
    c[i] = -INFF;
  }
  cin >> 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++) {
      c[i] = max(c[i], a[i] * b[j]);
    }
  }
  sort(c, c + n);
  printf("%I64d\n", c[n - 2]);
  return 0;
}
