#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double epx = exp(1.0);
const int maxn = 57;
long long a[maxn], b[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int m, n;
  long long ans1, ans2, ans;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(b, b + m);
  long long t1 = max(a[n - 1] * b[0], a[n - 1] * b[m - 1]);
  long long t2 = max(a[0] * b[0], a[0] * b[m - 1]);
  if (t1 > t2) {
    ans1 = max(a[n - 2] * b[0], a[n - 2] * b[m - 1]);
    ans2 = max(a[0] * b[0], a[0] * b[m - 1]);
    ans = max(ans1, ans2);
  } else {
    ans1 = max(a[1] * b[0], a[1] * b[m - 1]);
    ans2 = max(a[n - 1] * b[0], a[n - 1] * b[m - 1]);
    ans = max(ans1, ans2);
  }
  cout << ans << endl;
  return 0;
}
