#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
const ll INF = (1LL << 60) - 1;
clock_t begtime = clock();
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    ll n, m, i, j, k, ans = INF;
    cin >> n >> m;
    vector<ll> v(n), s(m);
    for (ll i = 0; i < n; i++) {
      cin >> v[i];
    }
    for (ll i = 0; i < m; i++) {
      cin >> s[i];
    }
    for (i = 0; i < n; i++) {
      ll now = (-INF);
      for (j = 0; j < n; j++) {
        if (i != j) {
          for (k = 0; k < m; k++) {
            now = max(now, (v[j] * s[k]));
          }
        }
      }
      ans = min(ans, now);
    }
    cout << ans;
  }
  return 0;
}
