This page is still under construction.

Parts of this page are still being built. What you see may change.

Moovie Mooving

Time limit1sMemory limit256 MB

Summary
Choose the fewest movies, each used at most once, whose showings chain together to cover every moment from time 0 to time L.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation, Greedy
Solved
No attempts yet

Problem

Bessie is at the movie theater. She wants to hide from Farmer John for the whole stretch of LL minutes from time 00 to time LL, so she has to be inside some showing at every moment of that stretch.

The theater plays NN movies. Movie ii runs for DiD_i minutes and has a fixed list of showtimes. A showing of movie ii that starts at time ss lasts from ss to s+Dis + D_i, and Bessie may walk in late and leave early, so that showing hides her at any moment between ss and s+Dis + D_i.

Bessie never watches the same movie twice, and she cannot move to another showtime of the movie she is already watching when that showtime overlaps the one she is in. Plots confuse her when she watches too many movies, so she wants to use as few movies as she can.

Decide whether Bessie can stay inside a showing from time 00 through time LL. If she can, report the smallest number of movies that lets her do it.

Input

The first line contains NN and LL.

Each of the next NN lines describes one movie. The line starts with the duration DD and the number of showtimes CC. The remaining CC integers on that line are the starting times of the showings of that movie. They are distinct, lie between 00 and LL, and are given in increasing order.

1≤N≤201 \le N \le 20, 1≤L≤1081 \le L \le 10^8, 1≤D≤L1 \le D \le L, 1≤C≤10001 \le C \le 1000.

Output

Print the smallest number of movies Bessie needs to watch to stay inside a showing from time 00 through time LL. Print −1-1 if no choice of movies works.

Hint

In the first example Bessie sits in the first showing of the fourth movie from time 00 to time 2020, then in the first showing of the first movie from time 2020 to time 6565, then in the last showing of the second movie from time 6565 to time 100100.

Examples2

  1. Example 1

    Input
    4 100
    50 3 15 30 55
    40 2 0 65
    30 2 20 90
    20 1 0
    
    Expected output
    3
    
  2. Example 2

    Input
    1 10
    5 1 0
    
    Expected output
    -1