#include <bits/stdc++.h>
using namespace std;
int main() {
  long long c, d, p, q, n, m, i, j, h;
  cin >> n >> m;
  long long a[n + 1];
  long long b[m + 1];
  int t = 1;
  int s = 1;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (j = 1; j <= m; j++) {
    cin >> b[j];
  }
  long long f = a[1] * b[1];
  for (p = 1; p <= n; p++) {
    for (q = 1; q <= m; q++) {
      if (a[p] * b[q] > f) {
        f = a[p] * b[q];
        t = p;
        s = q;
      }
    }
  }
  if (t != 1) {
    f = a[1] * b[1];
  } else {
    f = a[2] * b[1];
  }
  for (c = 1; c <= n; c++) {
    for (d = 1; d <= m; d++) {
      if ((a[c] * b[d] > f) && (c != t)) {
        f = a[c] * b[d];
      }
    }
  }
  cout << f << endl;
  return 0;
}
