#include <bits/stdc++.h>
using namespace std;
void files(bool in, char *s) {
  if (in)
    freopen(s, "r", stdin);
  else
    freopen(s, "w", stdout);
}
const double PI = 4 * atan(1.0);
const double EPS = 1e-9;
const int infi = (int)1e9;
const long long infl = (long long)1e17;
const int MOD = (int)1e9 + 7;
const int MAX = (int)2e5 + 22;
const int dx[] = {0, 1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 0, -1, 1, 1, -1, 1, -1};
const int kdx[] = {1, 1, -1, -1, 2, 2, -2, -2};
const int kdy[] = {2, -2, 2, -2, 1, -1, 1, -1};
long long n, m, x;
vector<long long> v, s;
vector<pair<long long, long long> > ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(x);
  }
  for (int i = 1; i <= m; i++) {
    cin >> x;
    s.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans.push_back(make_pair(v[i] * s[j], i));
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  long long res;
  long long err = ans[0].second;
  for (auto p : ans) {
    if (p.second == err) continue;
    res = p.first;
    break;
  }
  cout << res << "\n";
}
