#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[51];
vector<long long> t;
vector<long long> b;
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long k;
    cin >> k;
    t.push_back(k);
  }
  for (int i = 0; i < m; i++) {
    long long k;
    cin >> k;
    b.push_back(k);
  }
  for (int i = 0; i < n; i++) {
    long long Max = -1000000000000000001;
    for (int j = 0; j < m; j++) {
      if (Max < t[i] * b[j]) Max = t[i] * b[j];
    }
    a[i] = Max;
  }
  sort(a, a + n);
  cout << a[n - 2];
  return 0;
}
