#include <bits/stdc++.h>
using namespace std;
struct DATA {
  double h, a, d, s;
};
DATA make(double h, double a, double d, double s) {
  DATA data;
  data.h = h;
  data.a = a;
  data.d = d;
  data.s = s;
  return data;
}
bool compare(const DATA& x, const DATA& y) {
  if (x.a != y.a) return x.a > y.a;
  return x.s > y.s;
}
double solve(vector<DATA> data, DATA main, double hit) {
  sort(data.begin(), data.end(), compare);
  double max = main.h;
  double x, y;
  for (int i = 0; i < data.size(); ++i) {
    x = data[i].h / (main.a - data[i].d);
    if (modf(x, &y) != 0) ++y;
    main.h -= y * hit;
    if (main.s > data[i].s) main.h += data[i].a - main.d;
    if (main.h <= 0) return -1;
    hit -= data[i].a - main.d;
  }
  return max - main.h;
}
int main() {
  int i, n, ans;
  double h, a, d, s, hit;
  DATA main;
  vector<DATA> data;
  cin >> n;
  cin >> h >> a >> d >> s;
  main = make(h, a, d, s);
  for (i = 0, ans = 0, hit = 0; i < n; ++i) {
    cin >> h >> a >> d >> s;
    if (d >= main.a) ans = -1;
    if (ans == -1) continue;
    if (a <= main.d) continue;
    data.push_back(make(h, a, d, s));
    hit += a - main.d;
  }
  if (ans == -1)
    cout << ans << endl;
  else
    cout << (int)solve(data, main, hit) << endl;
  return 0;
}
