#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[100], b[100], maxi;
vector<long long> ans;
int main() {
  cin >> n >> m;
  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++) {
    maxi = -1e18;
    for (int j = 1; j <= m; j++) {
      maxi = max(maxi, a[i] * b[j]);
    }
    ans.push_back(maxi);
  }
  sort(ans.begin(), ans.end());
  cout << ans[n - 2];
}
