#include <bits/stdc++.h>
using namespace std;
const long long maxn = 550;
const long long INF = 0x3f3f3f3f;
const long long MOD = 1e9 + 7;
long long a[maxn];
long long b[maxn];
long long c[maxn];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  long long ans1, ans2, res;
  sort(a, a + n);
  sort(b, b + m);
  if (n > 2) {
    c[0] = max(a[0] * b[0], a[0] * b[m - 1]);
    c[1] = max(a[1] * b[0], a[1] * b[m - 1]);
    c[2] = max(a[n - 1] * b[0], a[n - 1] * b[m - 1]);
    c[3] = max(a[n - 2] * b[0], a[n - 2] * b[m - 1]);
    sort(c, c + 4);
    res = c[2];
  } else {
    ans1 = max(a[0] * b[0], a[0] * b[m - 1]);
    ans2 = max(a[1] * b[0], a[1] * b[m - 1]);
    res = min(ans1, ans2);
  }
  cout << res << endl;
  return 0;
}
