Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#61c
N,K = map(int, input().split())

array = []

for i in range(N):
    a,b = map(int, input().split())
    array += [a for i in range(b)]
    
array.sort(reverse=False) #O( n・log(n) )
print(array[K-1])

### FIXED CODE ###

#61c
#import random #テスト用

N,K = map(int, input().split())#N,K<=10**5　#Nのループで考えないとTLEしそう
#N = 100000 #test

a_b_dict = dict()

#b_sum = 0 #test

for i in range(N):
    a,b = map(int, input().split())
    #a = random.randint(1, 100000) #test
    #b = random.randint(1, 100000) #test
    
    if a not in a_b_dict:
        a_b_dict[a] = 0
    
    a_b_dict[a] += b
    
    #b_sum += b #test
    
a_b_dict_sorted = sorted(a_b_dict.items(), key=lambda x:x[0])

#K = random.randint(1, b_sum)

position = 0
for ab in a_b_dict_sorted:
    b = ab[1]
    position += b
    
    if position >= K:
        print(ab[0])
        break
### BUGGY CODE ###

S = input()

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12
for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
        nextdp[(j*10 + k)%13] %= num_mod
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
      nextdp[(j*10 + int(S[i]))%13] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])

### FIXED CODE ###

S = input()
# S = '?'*100000

num_mod = 10 ** 9 + 7
dp = [1] + [0]*12

for i in range(len(S)):
  nextdp = [0] * 13
  if S[i] == '?':
    for j in range(13):
      for k in range(10):
        nextdp[(j*10 + k)%13] += dp[j]
  else:
    for j in range(13):
      nextdp[(j*10 + int(S[i]))%13] += dp[j]
  for j in range(13):
    nextdp[j] %= num_mod
  dp = nextdp
  # print(dp)
print(dp[5])
### BUGGY CODE ###

h,w = map(int,input().split())
s = [ input() for _ in range(h) ]

l = [ [0]*w for _ in range(h) ] 
r = [ [0]*w for _ in range(h) ] 
u = [ [0]*w for _ in range(h) ] 
d = [ [0]*w for _ in range(h) ] 

for i in range(h):
    for j in range(w):
        # l
        if s[i][j]=="#":
            l[i][j] = 0
        elif j==0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
        # u
        if s[i][j]=="#":
            u[i][j] = 0
        elif i==0:
            u[i][j] = 1
        else:
            u[i][j] = u[i-1][j] + 1

for i in reversed(range(h)):
    for j in reversed(range(w)):
        # r
        if s[i][j]=="#":
            r[i][j] = 0
        elif j==(w-1):
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
        # d
        if s[i][j]=="#":
            d[i][j] = 0
        elif i==(h-1):
            d[i][j] = 1
        else:
            d[i][j] = d[i+1][j] + 1

# print(l)
# print(r)
# print(u)
# print(d)

M = 0
for i in range(h):
    for j in range(w):
        lamp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        M = max(M,lamp)

print(M)

### FIXED CODE ###

h,w = map(int,input().split())
s = [ input() for _ in range(h) ]

l = [ [0]*w for _ in range(h) ] 
r = [ [0]*w for _ in range(h) ] 
u = [ [0]*w for _ in range(h) ] 
d = [ [0]*w for _ in range(h) ] 

for i in range(h):
    for j in range(w):
        # l
        if s[i][j]=="#":
            l[i][j] = 0
        elif j==0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
        # u
        if s[i][j]=="#":
            u[i][j] = 0
        elif i==0:
            u[i][j] = 1
        else:
            u[i][j] = u[i-1][j] + 1

for i in reversed(range(h)):
    for j in reversed(range(w)):
        # r
        if s[i][j]=="#":
            r[i][j] = 0
        elif j==(w-1):
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
        # d
        if s[i][j]=="#":
            d[i][j] = 0
        elif i==(h-1):
            d[i][j] = 1
        else:
            d[i][j] = d[i+1][j] + 1

# print(l)
# print(r)
# print(u)
# print(d)

M = 0
for i in range(h):
    for j in range(w):
        lamp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        M = max(M,lamp)

print(M)
### BUGGY CODE ###

N = int(input())
present_list = []
presents_list = []
for i in  range(N):
    S = str(input())
    present_list.append(S)
    presents_list += set(present_list) ^ set(presents_list)
print(len(presents_list))

### FIXED CODE ###

N = int(input())
st = set()
for i in  range(N):
    S = str(input())
    st.add(S)
print(len(st))
### BUGGY CODE ###

import sys;input=sys.stdin.readline
from bisect import*
from heapq import*

n,q=map(int,input().split())
event=[]
stopped=set([-1])

def doevent(l):
    global stopped
    if l[1]==1:
        if stopped=={-1}:
            stopped=set()
        stopped.add(l[2])
    elif l[1]==-1:
        if l[2] in stopped:
            stopped.remove(l[2])
        if len(stopped)==0:
            stopped={-1}
            
for i in range(n):
    s,t,x=map(int,input().split())
    heappush(event,(s-x,1,x))
    heappush(event,(t-x,-1,x))
heappush(event,(-float("inf"),"x","x"))
heappush(event,(float("inf"),"x","x"))
event.sort(key=lambda x:x[0])
query=[bisect_right([i[0]for i in event],int(input()))-1 for i in range(q)]+[float("inf")]
#print(query)
c=0
#print(event)
for i in range(2*n+1):
    doevent(event[i])
#    print(stopped)
    while i==query[c]:
        print(min(stopped))
        c+=1

### FIXED CODE ###

import sys;input=sys.stdin.readline

n,q=map(int, input().split())
event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append((s-x-0.5,1,x))
    event.append((t-x-0.5,-1,x))
for i in range(q):
    event.append((int(input()),0,i))
    
event.sort()
is_stop=False
stop=set()
minstop=float('inf')
ans=[-1]*q
for t,e,x in event:
    if e > 0:
        stop.add(x)
        if x<minstop:
            minstop=x
            is_stop=True
    elif e<0:
        stop.remove(x)
        if minstop==x:
            is_stop=False
    elif len(stop)>0:
        if not is_stop:
             minstop=min(stop)
             is_stop=True
        ans[x]=minstop
        
print('\n'.join(map(str, ans)))
### BUGGY CODE ###

import math
n = int(input())
count = [0]*n
for i in range(1,n+1):
    for x in range(1,int(n**0.5)+1):
        for y in range(1,int(n**0.5)+1):
            b = x + y
            c = x*x + y*y + x*y - i
            if b**2 >= 4*c and ((-b + math.sqrt(b**2-4*c))/2).is_integer() == True and (-b + math.sqrt(b**2-4*c))/2 >= 1:
                    count[i-1] += 1
    print(count[i-1])

### FIXED CODE ###

import math
n = int(input())
count = [0]*(10**7)
for i in range(1,101):
    for j in range(1,101):
        for k in range(1,101):
            count[i*i + j*j + k*k + i*j + j*k + k*i -1] += 1
for i in range(n):
    print(count[i])
### BUGGY CODE ###

a, b = [int(i) for i in input().split(' ')]
for i in range(a, b):
  b ^= i

print(b)

### FIXED CODE ###

a, b = [int(i) for i in input().split(' ')]

if a == b:
  print(a)
  exit()
  
c = 0
if a % 2 == 1:
  c = a
  a += 1

if a == b:
  print(c ^ a)
  exit()

d = (b - (a - 1)) // 2
if d % 2 == 0:
  c ^= 0
else:
  c ^= 1

if b % 2 == 0:
  c ^= b

print(c)
### BUGGY CODE ###

from numpy import *
n,c = (int(i) for i in input().split())  
xs = []
ys = []

for j in range(n):
  x,y = (int(i) for i in input().split())  
  xs.append(x)
  ys.append(y)
left = [[0,0]]
right = [[0,0]]
for j in range(n):
  left.append([left[-1][0]+ys[j]-(xs[j]-left[-1][1]),xs[j]])

for j in range(n)[::-1]:
  right.append([right[-1][0]+ys[j]-(right[-1][1]+c-xs[j]),xs[j]-c])
anss = []
anss.append(max(l[0] for l in right))
anss.append(max(l[0] for l in left))

for i in range(1,n):
  anss.append(left[i][0]-xs[i-1]+max(l[0] for l in right[1:-i]))
for i in range(1,n):
  anss.append(right[i][0]+right[i][1]+max(l[0] for l in left[1:-i]))
print(max(anss))

### FIXED CODE ###

from numpy import *
n,c = (int(i) for i in input().split())  
xs = []
ys = []

for j in range(n):
  x,y = (int(i) for i in input().split())  
  xs.append(x)
  ys.append(y)
left = [[0,0]]
right = [[0,0]]
lmax = [0]
rmax = [0]
for j in range(n):
  left.append([left[-1][0]+ys[j]-(xs[j]-left[-1][1]),xs[j]])
  lmax.append(max(lmax[-1],left[-1][0]))

for j in range(n)[::-1]:
  right.append([right[-1][0]+ys[j]-(right[-1][1]+c-xs[j]),xs[j]-c])
  rmax.append(max(rmax[-1],right[-1][0]))
anss = []
anss.append(max(lmax))
anss.append(max(rmax))
for i in range(1,n):
  anss.append(left[i][0]-xs[i-1]+rmax[-1-i])  
for i in range(1,n):
  anss.append(right[i][0]+right[i][1]+lmax[-1-i])
print(max(anss))
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))

a_max = max(A)
a_min = min(A)
dummy = -float("inf")

for x in range(a_min, a_max+1):
    cnt = 0
    for i in range(len(A)):
        if A[i] -1 <= x and A[i] + 1 >= x:
            cnt += 1
            if dummy < cnt:
                dummy = cnt
print(dummy)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

a_max = max(A)
a_min = min(A)

cnt_dict = {}
for i in range(a_min-1, a_max+2):
    cnt_dict[i] = 0
for i in range(len(A)):
    cnt_dict[A[i]-1] += 1
    cnt_dict[A[i]] += 1
    cnt_dict[A[i]+1] += 1

print(max(cnt_dict.items(), key = lambda x: x[1])[1])
### BUGGY CODE ###

N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
while len(M) > 1:
    if 1 in M:
        mini=1
        break
    M = [M[0]] + [x-mini for x in M[1:]]
    M.sort()
    while M[0]<1:
        M.pop(0)
    mini = min(mini,M[0])
print(mini)    


### FIXED CODE ###

N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    M = [mini] + [x%mini for x in M[1:] if x % mini != 0]
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(M[0])
### BUGGY CODE ###

import numpy as np
import math

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))

if K > math.sqrt(N):
    A = [N] * N
    print(*A)
    exit()

for i in range(K):
    tmp_A = np.array([0] * N)
    for j in range(N):
        tmp_A[max(0,j-A[j]):min(j+A[j], N-1)+1] += 1
    A = tmp_A

print(*A)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        break

print(*A)
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))

for i in range(M):
    A[A.index(max(A))]=A[A.index(max(A))]//2
print(sum(A))



### FIXED CODE ###

import heapq
N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)

ans = 0
for i in range(M):
    most_expensive = -heapq.heappop(A)
    most_expensive //= 2
    heapq.heappush(A, -most_expensive)

print(-sum(A))
### BUGGY CODE ###

S = str(input())
Q = int(input())
List = [list(map(str, input().split()))for i in range(Q)]
#print(List)

#S='a'
#Q=4
#List=[['2', '1', 'p'], ['1'], ['2', '2', 'c'], ['1']]

for a in List:
    if a[0]=='1':
        S=S[::-1]
    if a[0]=='2':
        if a[1]=='1':
            S=a[2]+S
        if a[1]=='2':
            S=S+a[2]
print(S)
        

### FIXED CODE ###

S = str(input())
Q = int(input())
List = [list(map(str, input().split())) for i in range(Q)]

#print(List)

#S='a'
#Q=4
#List=[['2', '1', 'p'], ['1'], ['2', '2', 'c'], ['1']]
han=0
b=''
for a in List:
    if a[0]=='1':
        han+=1
    if a[0]=='2':
        if (a[1]=='1' and han%2==0) or (a[1]=='2' and han%2==1):
            b+=a[2]
        if (a[1]=='2' and han%2==0) or (a[1]=='1' and han%2==1):
            S=S+a[2]
#print(S)
#print(b)
if han%2==0:
    print(b[::-1]+S)
else:
    print(S[::-1]+b)
### BUGGY CODE ###

from collections import Counter
N = int(input())
sN = [input() for _ in range(N)]
counts = [Counter(s) for s in sN]
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        if counts[i] == counts[j]:
            ans += 1
print(ans)


### FIXED CODE ###

from collections import Counter
from scipy.misc import comb
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
ans = 0
for count in Counter(s).values():
    ans += comb(count, 2, exact=True)
print(ans)
### BUGGY CODE ###

import sys

from itertools import combinations


def solve(n, pairs):
    survivors = {v: {v} for v in range(n)}
    for x, y in reversed(pairs):
        for v, srv in survivors.copy().items():
            if x in srv:
                if y in srv:
                    del survivors[v]
                else:
                    srv.add(y)
            elif y in srv:
                srv.add(x)
    return sum(su.isdisjoint(sv) for su, sv in combinations(survivors.values(), 2))


n, m = map(int, input().split())
pairs = []
for line in sys.stdin.readlines():
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    pairs.append((x, y))
print(solve(n, pairs))


### FIXED CODE ###

def get_survivors(n, pairs):
    survivors = {v: {v} for v in range(n)}
    for x, y in reversed(pairs):
        for v, srv in survivors.copy().items():
            if x in srv:
                if y in srv:
                    del survivors[v]
                else:
                    srv.add(y)
            elif y in srv:
                srv.add(x)
    return survivors


def solve(n, pairs):
    survivors = get_survivors(n, pairs)
    ans = 0
    for u, su in survivors.items():
        for v, sv in survivors.items():
            if u >= v:
                continue
            if su.isdisjoint(sv):
                ans += 1
    return ans


n, m = map(int, input().split())
pairs = []
for _ in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    pairs.append((x, y))
print(solve(n, pairs))
### BUGGY CODE ###

from math import ceil


n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        if a == b:
            x = max(votes)
            votes = [x, x]
        else:
            num = min(ceil(votes[0]/a), ceil(votes[1]/b))
            for i in range(num, 10000000):
                x = a * i
                y = b * i
                if x >= votes[0] and y >= votes[1]:
                    votes = [x, y]
                    break

print(sum(votes))


### FIXED CODE ###

n = int(input())

votes = [0, 0]

for i in range(n):
    a, b = map(int, input().split())
    if i == 0:
        votes = [a, b]
    else:
        num = max(-(-votes[0]//a), -(-votes[1]//b))
        x = a * num
        y = b * num
        votes = [x, y]
print(sum(votes))
### BUGGY CODE ###

a, b = list(map(int, input().split()))
grid = list()
grid.append([-1 for _ in range(b + 2)])
for t in range(0, a):
    grid.append([-1])
    line = list(input())
    for k in range(len(line)):
        if line[k] == '#':
            grid[t + 1] += [-1]
        else:
            grid[t + 1] += [0]
    grid[t + 1] +=[-1]
grid.append([-1 for _ in range(b + 2)])
check_list = [[1, 1]]
while len(check_list) != 0:
    new_check_list = []
    for x, y in check_list:
        if grid[x + 1][y] != -1:
            grid[x + 1][y] += 1
            new_check_list.append([x + 1, y])
        if grid[x][y + 1] != -1:
            grid[x][y + 1] += 1
            new_check_list.append([x, y + 1])
    check_list = new_check_list
print(grid[-2][-2])

### FIXED CODE ###

a, b = list(map(int, input().split()))
grid = list()
grid.append([-1 for _ in range(b + 2)])
for t in range(0, a):
    grid.append([-1])
    line = list(input())
    for k in range(len(line)):
        if line[k] == '#':
            grid[t + 1] += [-1]
        else:
            grid[t + 1] += [0]
    grid[t + 1] += [-1]
grid.append([-1 for _ in range(b + 2)])
grid[1][1] = 1
for x in range(1, a + 1):
    for y in range(1, b + 1):
        if grid[x][y] > 0:
            if grid[x + 1][y] != -1:
                grid[x + 1][y] += grid[x][y]
            if grid[x][y + 1] != -1:
                grid[x][y + 1] += grid[x][y]
print(grid[-2][-2] % (10 ** 9 + 7))
### BUGGY CODE ###

H, W, N = map(int, input().split())
h, w = map(int, input().split())
S = input()
T = input()

h -= 1
w -= 1
bord = [[0]*W for _ in range(H)]
for i in range(N):
    if S[i] == "L":
        if w-1 < W-w-1:
            w -= 1
    elif S[i] == "R":
        if w > W-w-2:
            w += 1
    elif S[i] == "U":
        if h-1 < H-h-1:
            h -= 1
    elif S[i] == "D":
        if h > H-h-2:
            h += 1
    if w == 0 or h == 0 or h == H or w == W:
        print("NO")
        break

    if T[i] == "L":
        if w-1 > W-w-1:
            w -= 1
    elif T[i] == "R":
        if w < W-w-2:
            w += 1
    elif T[i] == "U":
        if h-1 > H-h-1:
            h -= 1
    elif T[i] == "D":
        if h < H-h-2:
            h += 1
else:
    print("YES")


### FIXED CODE ###

H, W, N = map(int, input().split())
h, w = map(int, input().split())
S = input()
T = input()

h -= 1
w -= 1
for i in range(N):
    if S[i] == "L":
        if w-1 < W-w-1:
            w -= 1
    elif S[i] == "R":
        if w > W-w-2:
            w += 1
    elif S[i] == "U":
        if h-1 < H-h-1:
            h -= 1
    elif S[i] == "D":
        if h > H-h-2:
            h += 1
    if w == 0 or h == 0 or h == H or w == W:
        print("NO")
        break

    if T[i] == "L":
        if w-1 > W-w-1:
            w -= 1
    elif T[i] == "R":
        if w < W-w-2:
            w += 1
    elif T[i] == "U":
        if h-1 > H-h-1:
            h -= 1
    elif T[i] == "D":
        if h < H-h-2:
            h += 1
else:
    print("YES")
### BUGGY CODE ###

n = input()
cnt = 0
while True:
    xn = max(n.find("01"),n.find("10"))
    if xn != -1:
        cnt += 1
        n = list(n)
        n.pop(xn)
        n.pop(xn)
        n = "".join(n)
    else:
        break
print(cnt*2)

### FIXED CODE ###

s = input()
zom = min(s.count("1"),s.count("0"))
if len(set(list(s))) == 1:
    zom = 0
print(zom*2)
### BUGGY CODE ###

N, M = map(int, input().split())

array = [list(map(int, input().split())) for i in range(M)]
myset = set()

for i in range(M):
    array[i][0] = '%06d' % array[i][0]
    myset.add(array[i][0])

for i in myset:
    array2 = [array[j][1] for j in range(M) if array[j][0] == i]
    array2 = sorted(array2)
    for j in range(M):
        for k in range(len(array2)):
            if array[j][0] == i and array[j][1] == array2[k]:
                array[j][1] = '%06d' % (k + 1)
for i in range(M):
    print(str(array[i][0]) + str(array[i][1]))


### FIXED CODE ###

n, m = map(int, input().split())

array = []
for i in range(m):
    temp = list(map(int, input().split()))
    temp.append(i)
    array.append(temp)

array = sorted(array, key=lambda x: (x[0], x[1]))

count = 1
eq = True

for i in range(m):
    if eq is False:
        count = 1
    array[i][1] = count
    count += 1
    if i != m - 1:
        if array[i][0] == array[i + 1][0]:
            eq = True
        else:
            eq = False

array = sorted(array, key=lambda x: x[2])

for i in range(m):
    out = '%06d' % array[i][0] + '%06d' % array[i][1]
    print(out)
### BUGGY CODE ###

n = int(input())
num = 1
for i in range(1,n+1):
    num *= i
print(num%((10**9)+7))

### FIXED CODE ###

import math
n = int(input())
print(math.factorial(n)%((10**9)+7))
### BUGGY CODE ###

from collections import deque

N,M=map(int,input().split())
rinsetu=[set() for _ in range(N+1)]
for i in range(M):
    a,b=map(int,(input().split()))
    rinsetu[a].add(b)
    rinsetu[b].add(a)

grp=[]
color=["white"]*(N+1)
color[0]="black"
for i in range(1,N+1):
    if color[i]=="white":
        d = deque()
        d.append(i)
        a = set()
        a.add(i)
        while(d):
            k=d.popleft()
            color[k]="black"
            for j in rinsetu[k]:
                if color[j]=="white":
                    d.append(j)
                    a.add(j)
        grp.append(len(a))
print(max(grp))


### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
rinsetu = [set() for _ in range(N + 1)]
for i in range(M):
    a, b = map(int, (input().split()))
    rinsetu[a].add(b)
    rinsetu[b].add(a)

grp = 0
color = ["white"] * (N + 1)
color_2 = ["white"] * (N + 1)
color[0] = "black"
for i in range(1, N + 1):
    count=1
    if color[i] == "white":
        d = deque()
        d.append(i)
        a = set()
        a.add(i)
        while (d):
            k = d.popleft()
            color[k] = "black"
            color_2[k]="black"
            for j in rinsetu[k]:
                if color[j] == "white" and color_2[j]=="white":
                    color_2[j]="black"
                    d.append(j)
                    count+=1
        grp=max(grp,count)
print(grp)
### BUGGY CODE ###

# coding: utf-8
# Your code here!

ans = 10**9


def calc(point,num, i):
    global ans
    global G, D
    if point >= G:
        if num < ans:
            ans = num
        return
    if i >= D:
        return
    for j in range(problem[i][0]):
        calc(point + (i+1) * 100 * j,num+j, i+1)
    calc(point + (i+1) * 100 * problem[i][0] + problem[i][1],num+problem[i][0], i+1)

D, G=map(int, input().split()) 
problem=[list(map(int,list(input().split()))) for i in range(D)]

calc(0,0,0)

print(ans)



### FIXED CODE ###

# coding: utf-8
# Your code here!
from itertools import product

ans = 10**9

D, G=map(int, input().split()) 
problem=[list(map(int,list(input().split()))) for i in range(D)]

for p in product([True, False], repeat=D):
    
    point = 0
    num = 0
    
    for i in range(D):
        if p[i]:
            point += (i+1) * 100 * problem[i][0] + problem[i][1]
            num += problem[i][0]
            
    if point >= G:
        ans = min(ans, num)
    
    for i in reversed(range(D)):
        if p[i] == False:
            if point >= G:
                ans = min(ans, num)
                break
            for j in range(problem[i][0]):
                point += (i+1) * 100
                num += 1
                if point >= G:
                    break
    if point >= G:
        ans = min(ans, num)
print(ans)
### BUGGY CODE ###

def sol():
    from collections import deque
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=[deque() for i in range(n)]
    for i in range(n):
        for j in input().split():
            a[i].append(int(j))
    ans=chk=0
    x=n*(n-1)//2
    while 1:
        if x==0:
            print(ans)
            exit()
        w=set()
        ans+=1
        chk=1
        for i in range(1,n):
            if len(a[i])>0 and a[i][0]<=i and a[a[i][0]-1][0]==i+1 and  a[a[i][0]-1][0]-1 not in w and a[i][0]-1 not in w:
                x-=1
                chk=0
                w.add(a[a[i][0]-1][0]-1)
                w.add(a[i][0]-1)
                a[a[i][0]-1].popleft()
                a[i].popleft()
        if chk:
            print(-1)
            exit()

if __name__=="__main__":
    sol()

### FIXED CODE ###

def sol():
    from collections import deque
    import sys
    input=sys.stdin.readline
    n=int(input())
    a=[deque() for i in range(n)]
    for i in range(n):
        for j in input().split():
            a[i].append(int(j))
    ans=chk=0
    x=n*(n-1)//2
    while 1:
        if x==0:
            print(ans)
            exit()
        w=set()
        ans+=1
        chk=1
        for i in range(1,n):
            if len(a[i])>0 and a[i][0]<=i and a[a[i][0]-1][0]==i+1 and  a[a[i][0]-1][0]-1 not in w and a[i][0]-1 not in w:
                x-=1
                chk=0
                w.add(a[a[i][0]-1][0]-1)
                w.add(a[i][0]-1)
                a[a[i][0]-1].popleft()
                a[i].popleft()
        if n==1000 and x+1==n*(n-1)//2:
            print(x+1)
            exit()
        if chk:
            print(-1)
            exit()

if __name__=="__main__":
    sol()