#include <bits/stdc++.h>
using namespace std;
long long arr1[60], arr2[60], arr[60], n, m, p1 = -1e18, p2 = -1e18;
int main() {
  fill(arr, arr + 60, -1e18);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> arr1[i];
  for (int i = 1; i <= m; i++) cin >> arr2[i];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) arr[i] = max(arr[i], arr1[i] * arr2[j]);
    if (arr[i] >= p1)
      p2 = p1, p1 = arr[i];
    else if (arr[i] > p2)
      p2 = arr[i];
  }
  cout << p2 << endl;
  return 0;
}
