#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
long long a[55], b[55];
struct c {
  long long cc;
  long long aa;
  bool flag;
} C[3000];
map<long long, long long> cnt;
bool cmp(c i, c j) { return i.cc < j.cc; }
int main() {
  int n, m;
  int k = 0;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  for (int i = 0; i < m; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      C[k].cc = a[i] * b[j];
      C[k++].aa = a[i];
    }
  for (int i = 0; i < k; ++i) {
    C[i].flag = false;
    if (cnt[C[i].aa] > 1) {
      C[i].flag = true;
    }
  }
  sort(C, C + k, cmp);
  for (int j = k - 2; j >= 0; --j) {
    if (C[j].aa != C[k - 1].aa || C[j].flag == true) {
      cout << C[j].cc << endl;
      break;
    }
  }
  return 0;
}
