#include <bits/stdc++.h>
using namespace std;
long long a[55], b[55];
long long c[55];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> b[i];
  int flag = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        c[i] = a[i] * b[j];
      else
        c[i] = max(c[i], a[i] * b[j]);
    }
  }
  sort(c + 1, c + n + 1);
  cout << c[n - 1] << endl;
  return 0;
}
