#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 3e5 + 5;
const double pi = acos(-1.0);
const int mod = 998244353;
struct something {
  int num, period, time;
  bool operator<(const something& y) const {
    return y.time < time || (y.time == time && y.num < num);
  }
  something() {}
  something(int num, int period, int time)
      : num(num), period(period), time(time) {}
};
int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
map<int, int> mp1, mp2;
map<pair<int, int>, int> mp3;
vector<pair<int, int> > p;
vector<int> a, b;
signed main() {
  int n, m;
  cin >> n >> m;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  for (int i = 0; i < m; i++) {
    cin >> x;
    b.push_back(x);
  }
  long long res = 9e18;
  for (int i = 0; i < n; i++) {
    long long num = -9e18;
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      for (int k = 0; k < m; k++) num = max(num, 1LL * a[j] * b[k]);
    }
    res = min(res, num);
  }
  cout << res << endl;
  return 0;
}
