#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int M[1000],L[1000],K[1000];
bool flag[1000];
int N, T;
int owaru[1001];

bool check(int num) {
  int aki = num;
  memset(flag,0,sizeof(flag));
  memset(owaru,0,sizeof(owaru));
  int cnt = 0;
  REP(i,T) {
    aki += owaru[i];
    REP(j,N) {
      if (aki == 0) break;
      if (flag[j]) continue;
      if (i%(L[j]+K[j]) <= L[j]) {
        if (i+M[j]>T) return 0;
        aki--;
        owaru[i+M[j]]++;
        cnt++;
        flag[j] = 1;
        if (cnt == N) return 1;
      }
    }
  }
  return 0;
}

int main() {
  while(cin>>N>>T,N||T) {
    REP(i,N) {
      cin >> M[i] >> L[i] >> K[i];
    }
    int ans = -1;
    for (int i=1; i<=N; ++i) {
      if (check(i)) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
}