#include <bits/stdc++.h>
using namespace std;
bool isPerfectSquare(int x) {
  int s = sqrt(x);
  return (s * s == x);
}
bool isFibonacci(int n) {
  return isPerfectSquare(5 * n * n + 4) || isPerfectSquare(5 * n * n - 4);
}
bool odd(int a, int b, int c) {
  if (a + b > c && a + c > b && b + c > a) return true;
  return false;
}
bool getS(int n) {
  int s = 0;
  bool b;
  while (n) {
    s += n % 10;
    n /= 10;
  }
  (s == 10) ? b = true : b = false;
  return b;
}
vector<int> v;
bool checkDuplicates(vector<int> array, int n) {
  sort(array.begin(), array.end());
  int i;
  for (i = 0; i < n - 1; i++) {
    if (array[i] == array[i + 1]) return true;
  }
  return false;
}
int main() {
  long long n, m, x, y;
  vector<long long> v, v1, v2;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    v.push_back(x);
  }
  for (int i = 0; i < m; ++i) {
    cin >> y;
    v1.push_back(y);
  }
  for (int i = 0; i < n; ++i) {
    long long int ans = -2e18;
    for (int j = 0; j < m; ++j) {
      ans = max(ans, v[i] * v1[j]);
    }
    v2.push_back(ans);
  }
  sort(v2.begin(), v2.end());
  cout << v2[n - 2];
}
