from heapq import heappush, heappop n, y, z = map(int, input().split()) clx = [tuple(map(int, input().split())) for _ in range(n)] clx.sort(key=lambda x: x[1]) clx.append((1, 10**18+1, 1)) h = [] for i in range(n): if clx[i][1] <= y: heappush(h, (-clx[i][2], clx[i][0])) else: break ans = 0 while y < z: nxtl = clx[i][1] if h: x, c = heappop(h) x = -x if y + c * x >= z and z <= nxtl + x: ans += (z - y + x - 1) // x print(ans) exit() if y + c * x < nxtl: ans += c y += c * x else: ans += (nxtl - y + x - 1) // x y += ((nxtl - y + x - 1) // x) * x heappush(h, (-x, c - (nxtl - y + x - 1) // x)) else: print(-1) exit() # print(y, ans,h) while clx[i][1] <= y: heappush(h, (-clx[i][2], clx[i][0])) i += 1