#include <bits/stdc++.h>
using namespace std;
long long a[55], b[55], res[100];
int main() {
  int n, m;
  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]);
  }
  sort(a, a + n);
  sort(b, b + m);
  res[0] = a[0] * b[0];
  res[1] = a[n - 1] * b[m - 1];
  res[2] = a[0] * b[m - 1];
  res[3] = a[n - 1] * b[0];
  res[4] = a[1] * b[0];
  res[5] = a[n - 2] * b[m - 1];
  res[6] = a[1] * b[m - 1];
  res[7] = a[n - 2] * b[0];
  long long _RES = *max_element(res, res + 4);
  if (_RES == res[0] || _RES == res[2])
    cout << max(max(res[1], res[3]), max(res[4], res[6])) << endl;
  else
    cout << max(max(res[0], res[2]), max(res[5], res[7])) << endl;
  return 0;
}
