#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> b[i];
  }
  long long ans = 1e18;
  for (int i = 0; i < n; ++i) {
    long long cur = -1e18;
    for (int j = 0; j < n; ++j) {
      if (j != i) {
        for (int k = 0; k < m; ++k) {
          cur = max(cur, (long long)b[k] * a[j]);
        }
      }
    }
    ans = min(ans, cur);
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
