#include <bits/stdc++.h>
using namespace std;
struct temp {
  long long val;
  long long a, b;
};
bool comp(temp x, temp y) { return x.val > y.val; }
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> v1(n), v2(m);
  for (long long i = 0; i < n; i++) {
    cin >> v1[i];
  }
  for (long long j = 0; j < m; j++) {
    cin >> v2[j];
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  temp tt[2502];
  int it = 0;
  temp ts;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      ts.val = v1[i] * v2[j];
      ts.a = i;
      ts.b = j;
      tt[it++] = ts;
    }
  }
  sort(tt, tt + it, comp);
  long long del = tt[0].a;
  for (long long i = 0; i < it; i++) {
    if (tt[i].a != del) {
      cout << tt[i].val << '\n';
      return 0;
    }
  }
}
