#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long int> a(n);
  vector<long long int> b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  int ti = 0;
  long long int mx = a[0] * b[0];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      long long int tmp = a[i] * b[j];
      if (mx < tmp) {
        mx = tmp;
        ti = i;
      }
    }
  }
  long long int ans = a[0] * b[0];
  if (ti == 0) ans = a[1] * b[1];
  for (int i = 0; i < n; i++) {
    if (i == ti) continue;
    for (int j = 0; j < m; j++) {
      long long int tmp = a[i] * b[j];
      if (ans < tmp) {
        ans = tmp;
      }
    }
  }
  cout << ans << endl;
}
