#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
static long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) {
  long long temp = gcd(a, b);
  return temp ? (a / temp * b) : 0;
}
unsigned long long PowMod(unsigned long long x, unsigned long long e,
                          unsigned long long mod) {
  unsigned long long res;
  if (e == 0) {
    res = 1;
  } else if (e == 1) {
    res = x;
  } else {
    res = PowMod(x, e / 2, mod);
    res = res * res % mod;
    if (e % 2) res = res * x % mod;
  }
  return res;
}
int solve() {
  int n, m;
  cin >> n >> m;
  long long a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
  }
  vector<pair<long long, int> > v;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      v.push_back(make_pair(a[i] * b[j], i));
    }
  }
  sort((v).begin(), (v).end());
  int I = v[(n * m) - 1].second;
  long long ans = (1000000000LL) * (1000000000LL) * (-1LL);
  ans--;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (i != I) {
        ans = max(ans, a[i] * b[j]);
      }
    }
  }
  cout << ans;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
