#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  long long arr1[n];
  long long arr2[m];
  for (int i = 0; i < n; i++) cin >> arr1[i];
  for (int j = 0; j < m; j++) cin >> arr2[j];
  sort(arr1, arr1 + n);
  sort(arr2, arr2 + m);
  long long largest[n];
  for (int i = 0; i < n; i++) {
    largest[i] = -1000000000000000000;
    for (int j = 0; j < m; j++) {
      largest[i] = max(largest[i], arr1[i] * arr2[j]);
    }
  }
  sort(largest, largest + n);
  cout << largest[n - 2] << "\n";
}
