#include <bits/stdc++.h>
using namespace std;
struct Info {
  long long int HP, attack, guard, speed;
};
struct Data {
  Data(int arg_enemy_index, long long int arg_rest_count,
       long long int arg_promised_damage) {
    enemy_index = arg_enemy_index;
    rest_count = arg_rest_count;
    promised_damage = arg_promised_damage;
  }
  bool operator<(const struct Data &arg) const {
    return promised_damage < arg.promised_damage;
  }
  int enemy_index;
  long long int rest_count, promised_damage;
};
int N;
Info Hero, monster[40000];
long long int start_HP, to_hero_damage[40000];
int main() {
  scanf("%d", &N);
  scanf("%lld %lld %lld %lld", &Hero.HP, &Hero.attack, &Hero.guard,
        &Hero.speed);
  start_HP = Hero.HP;
  long long int give_damage, promised_count;
  priority_queue<Data> Q;
  long long int to_hero_damage_sum = 0;
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld %lld %lld", &monster[i].HP, &monster[i].attack,
          &monster[i].guard, &monster[i].speed);
    if (monster[i].attack <= Hero.guard) {
      continue;
    }
    to_hero_damage[i] = monster[i].attack - Hero.guard;
    to_hero_damage_sum += to_hero_damage[i];
    give_damage = Hero.attack - monster[i].guard;
    if (monster[i].guard >= Hero.attack) {
      printf("-1\n");
      return 0;
    }
    if (monster[i].speed > Hero.speed) {
      if (monster[i].HP % give_damage == 0) {
        promised_count = monster[i].HP / give_damage;
      } else {
        promised_count = monster[i].HP / give_damage + 1;
      }
    } else {
      if (monster[i].HP % give_damage == 0) {
        promised_count = monster[i].HP / give_damage - 1;
      } else {
        promised_count = monster[i].HP / give_damage;
      }
    }
    if (promised_count > 0) {
      Q.push(Data(i, promised_count, to_hero_damage[i] * promised_count));
    }
  }
  while (!Q.empty()) {
    Hero.HP -= to_hero_damage_sum;
    if (Hero.HP <= 0) break;
    if (Q.top().rest_count == 1) {
      to_hero_damage_sum -= to_hero_damage[Q.top().enemy_index];
      Q.pop();
      continue;
    }
    Q.push(
        Data(Q.top().enemy_index, Q.top().rest_count - 1,
             to_hero_damage[Q.top().enemy_index] * (Q.top().rest_count - 1)));
    Q.pop();
  }
  if (Hero.HP <= 0) {
    printf("-1\n");
  } else {
    printf("%lld\n", start_HP - Hero.HP);
  }
  return 0;
}
