Under construction

Still being built. Things may change

Data Structures Are Really the Best

Interview

Time limit1sMemory limit1024 MB

Summary
Given M stacks of distinct books numbered 1 to N, decide whether repeatedly taking only top books can yield the order 1, 2, ..., N.
Level

Medium5 of 10

Topics
Stack, Simulation, Implementation, Greedy
Solved
No attempts yet

Problem

After learning about stacks, Chanwoo fell in love with the data structures course.

Having resolved to devote himself to the data structures course alone, Chanwoo piled the textbooks of his other NN courses carelessly in a corner of his room as MM stacks. But as the midterm exam approached, he could no longer study only data structures, so he decided to tidy up the abandoned textbooks of his other courses and arrange them in numerical order.

The NN textbooks are numbered from 11 to NN. Chanwoo can take only the textbook at the top of each stack, and since he must lay them out in the order he takes them, he has to take textbook 11, then 22, ..., then N−1N - 1, then NN to arrange them in numerical order. Chanwoo says he will give up studying for the midterm if he cannot arrange the textbooks correctly. Write a program that tells him whether he can arrange them in numerical order.

Input

The first line gives the number of textbooks NN and the number of textbook stacks MM.

From the second line, 2×M2\times M lines give information about each stack.

For the ii-th stack, the first line gives the number of textbooks kik_{i} in the stack, and the second line gives kik_{i} integers separated by spaces.

Each integer is a textbook number, given starting from the textbook at the bottom.

Each integer from 11 to NN appears exactly once as a textbook number.

Output

Print Yes if the textbooks can be taken in the correct order, and No otherwise.

Constraints

  • 1≤M≤N≤200 0001 \leq M \leq N \leq 200\,000
  • 1≤ki1 \leq k_i
  • The sum of all kik_{i} is always NN.

Examples2

  1. Example 1

    Input
    4 2
    2
    3 1
    2
    4 2
    
    Expected output
    Yes
    
  2. Example 2

    Input
    5 2
    3
    3 5 1
    2
    4 2
    
    Expected output
    No