Under construction

Still being built. Things may change

Museum Tour

Interview

Time limit2sMemory limit1024 MB

Summary
Given each kitten's viewing order, find the hall where the entrance minimizes the total walking distance for all kittens, choosing the smallest number on ties.
Level

Medium4 of 10

Topics
Prefix sum, Greedy, Array
Solved
No attempts yet

Problem

NN kittens are going on a museum tour, and each has planned the order in which to view the exhibits. The museum is a row of MM exhibit halls, and the ii-th hall from the left holds exhibit ii. (1≤i≤M)(1 \le i \le M)

Every kitten enters through the entrance, views the exhibits in the order it wants, and then leaves through the entrance. The distance between the ii-th and jj-th halls is ∣j−i∣|j - i|.

Chunbae

Chunbae, the museum director, wants to place the entrance in one of the MM halls. Chunbae wants the spot where the sum of all kittens' travel distances is smallest, but the museum is large and choosing that spot is hard.

Given the viewing plans of the NN kittens, write a program that computes where the entrance should be placed.

Input

The first line contains NN and MM, separated by a space. (2≤N,M≤200 000)(2 \le N, M \le 200\,000)

The next NN lines describe the kittens' viewing plans. Each line has the following form.

  • k p_1 p_2 ⋯ p_kk\ p\_1\ p\_2\ \cdots\ p\_k: the kitten enters through the entrance, views exhibits p_1,p_2,⋯ ,p_kp\_1, p\_2, \cdots, p\_k in that order, and then leaves through the entrance. (2≤k≤10(2 \le k \le 10, 1≤p_i≤M)1 \le p\_i \le M)

Output

Print the number of the exhibit hall where the entrance should be placed. If several halls work, print the smallest number.

Examples1

  1. Example 1

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