#include <bits/stdc++.h>
using namespace std;
long long n, m, a[51], b[51], c[51], cnt = 0, res = -1e18;
int main() {
  cin >> n >> m;
  priority_queue<long long> pq;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    res = -1e18;
    for (int j = 1; j <= m; j++) {
      res = max(res, a[i] * b[j]);
    }
    pq.push(res);
  }
  pq.pop();
  cout << pq.top();
}
