#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n, m, k = 0, cp = 0;
  long long a[50], b[50], p[2500], cmax = -1000000000000000000;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < m; j++) {
    cin >> b[j];
    for (int i = 0; i < n; i++) {
      if (cmax < a[i] * b[j]) {
        cp = i;
        cmax = a[i] * b[j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != cp) {
      for (int j = 0; j < m; j++) {
        p[k] = a[i] * b[j];
        k++;
      }
    }
  }
  sort(p, p + (n - 1) * m);
  cout << p[(n - 1) * m - 1];
  return 0;
}
