Harryxun/stf_run huggingface dataset:
N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]

answer=[]

if N==1:
    for j in range(10):
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
else:
    for j in range(10**(N-1),10**N):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
if len(answer)>=1:
    print(min(answer))
    #print(answer)
else:
    print(-1)


### FIXED CODE ###

N,M=map(int,input().split())
sc=[list(map(int,input().split())) for _ in range(M)]

answer=[]

if N==1:
    for j in range(10):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
else:
    for j in range(10**(N-1),10**N):
        a=0
        for i in range(M):
            if int(str(j)[sc[i][0]-1])==sc[i][1]:
                a+=1
            else:
                break
        if a==M:
            answer.append(j)
if len(answer)>=1:
    print(min(answer))
    #print(answer)
else:
    print(-1)
O = str(input())
E = str(input())
st = ''
for i in range(len(O)):
    st += O[i]
    st+= E[i]
    
print(st)
        

### FIXED CODE ###

O = str(input())
E = str(input())
st = ''
if len(O) == len(E):
    for i in range(len(O)):
        st += O[i]
        st+= E[i]
    print(st)
else:
    for i in range(len(O)-1):
        st += O[i]
        st+= E[i]
    
    print(st+O[-1])
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#006
import numpy as np

def main():
	n,m,q=MI()
	li=np.zeros((n+1,n+1),dtype=np.int64)
	for _ in range(m):
		l,r=MI()
		li[l][r]+=1
	#print(li)

	li=np.cumsum(li,axis=0)
	li=np.cumsum(li,axis=1)
	#print(li)

	for _ in range(q):
		p,q=MI()
		print(li[q,q]-li[p-1,q]-li[q,p-1]+li[p-1,p-1])

if __name__ == "__main__":
	main()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#006
import numpy as np

def main():
	n,m,q=MI()
	li=np.zeros((n+1,n+1),dtype=np.int64)
	for _ in range(m):
		l,r=MI()
		li[l][r]+=1
	#print(li)

	li=np.cumsum(li,axis=0)
	li=np.cumsum(li,axis=1)
	#print(li)

	for _ in range(q):
		p,q=MI()
		print(li[q,q]-li[p-1,q]-li[q,p-1]+li[p-1,p-1])

if __name__ == "__main__":
	main()
N, M = map(int, input().split())

seki = set(list(range(1,N+1)))
for i in range(M):
    l, r = map(int, input().split())
    seki &= set(list(range(l, r+1)))
print(len(seki))

### FIXED CODE ###

# 解説を見ての解答
from sys import stdin

n, m = map(int, stdin.readline().rstrip().split())
lr = [list(map(int, stdin.readline().rstrip().split())) for i in range(m)]

l, r = lr[0][0], lr[0][1]
for i in range(m):
    l = max(l, lr[i][0])
    r = min(r, lr[i][1])

print(max(0,r-l+1))
a, b　= map(int, input().split())
c = a*b

if c%2 == 0:
  print ("Even")
else:
  print ("Odd")

### FIXED CODE ###

a, b = map(int, input().split())
c = a * b

if c % 2 == 0:
    print("Even")
else:
    print("Odd")
import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    x[a].append(-b)
y=heapq.heapify([])
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
x={}
for i in range(M+1):
    x[i]=[]
for i in range(N):
    a,b=map(int,input().split())
    if a>M:
        continue
    x[a].append(-b)
y=[]
an=0
for i in range(M+1):
    for n in x[i]:
        heapq.heappush(y,n)
    try:
        an-=heapq.heappop(y)
    except:
        pass
print(an)
for i in xrange(0,n-m+1):
  for j in xrange(0, n-m+1):
    flag = True
    for x in xrange(0, m):
      for y in xrange(0, m):
        if mp[x][y] != np[i+x][j+y]:
          flag = False
          break
      if flag == False:
        break
    if flag:
      print "Yes"
      break
  if flag: break
if flag==False: print "No"

### FIXED CODE ###

n,m = map(int, raw_input().split())
np=[]
mp=[]
for i in xrange(0, n):
  np.append(raw_input())
for i in xrange(0, m):
  mp.append(raw_input())
 
for i in xrange(0,n-m+1):
  for j in xrange(0, n-m+1):
    flag = True
    for x in xrange(0, m):
      for y in xrange(0, m):
        if mp[x][y] != np[i+x][j+y]:
          flag = False
          break
      if flag == False:
        break
    if flag:
      print "Yes"
      break
  if flag: break
if flag==False: print "No"
import sys

sys.setrecursionlimit(10000000)

n,k=[int(i) for i in input().split()]
modnum=1000000007
Cnklist=[0 for i in range(2001)]
def Cnk(i):
    if Cnklist[i]!=0:
        return Cnklist[i]
    if i==0:
        Cnklist[0]=1
        return 1
    if i==1:
        Cnklist[1]=n-k+1
        return n-k+1
    Cnklist[i]=int((n-k+2-i)*Cnk(i-1)/i)
    return Cnklist[i]

Cklist=[0 for i in range(2001)]
def Ck(i):
    if Cklist[i]!=0:
        return Cklist[i]
    if i==0:
        Cklist[0]=1
        return 1
    if i==1:
        Cklist[1]=k-1
        return k-1
    Cklist[i]=int((k-i)*Ck(i-1)/i)
    return Cklist[i]

for i in range(1,k+1):
    print(Cnk(i)*Ck(i-1)%modnum)

### FIXED CODE ###

import sys

sys.setrecursionlimit(10000000)

#ボールの数、青いボールの数を書く
n,k=[int(i) for i in input().split()]

#modnum 定義
modnum=1000000007

#dp用のコンビネーションリスト
Cnklist=[None for i in range(2001)]
def Cnk(i):
    if Cnklist[i]!=None:
        return Cnklist[i]
    if i==0:
        Cnklist[0]=1
        return 1
    Cnklist[i]=(n-k+2-i)*Cnk(i-1)//i
    return Cnklist[i]

#dp用のコンビネーションリスト
Cklist=[None for i in range(2001)]
def Ck(i):
    if Cklist[i]!=None:
        return Cklist[i]
    if i==0:
        Cklist[0]=1
        return 1
    Cklist[i]=(k-i)*Ck(i-1)//i
    return Cklist[i]


for i in range(1,k+1):
    print((Cnk(i)*Ck(i-1))%modnum)
N, A, B = list(map(int, input().split()))
ans = max(A * T, B)

print(ans)


### FIXED CODE ###

N, A, B = list(map(int, input().split()))
ans = min(A * N, B)

print(ans)
def search(arr, num, i):
  nxt = arr[num]
  if(nxt == 1):
    return i
  elif(i >= len(arr)):
    return -1
  else:
    return search(arr, nxt, i+1)

n = int(input())
a = [ int(input()) - 1 for _ in range(n)]
print(search(a, 0, 1))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
def search(arr, num, i):
  nxt = arr[num]
  if(nxt == 1):
    return i
  elif(i >= len(arr)):
    return -1
  else:
    return search(arr, nxt, i+1)

n = int(input())
a = [ int(input()) - 1 for _ in range(n)]
print(search(a, 0, 1))
n,m = map(int,input().split())
t='000'
if n==2: t='010'
if n==3: t='100'
f=[0]*len(t)
t=[int(t[0]),int(t[1]),int(t[2])]
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s=s-(n-2)
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)

### FIXED CODE ###

n,m = map(int,input().split())
t='000'
if n==2: t='010'
if n==3: t='100'
f=[0]*len(t)
t=[int(t[0]),int(t[1]),int(t[2])]
ans = t[0]*100+t[1]*10+t[2] 
for i in range(m):
    ans = -1
    s,c = map(int,input().split())
    s=s-(n-2)
    if c <  t[s]: break
    if c >  t[s]:
        if f[s]==0:
            f[s],t[s]=1,c
        elif f[s]==1:
            break
    ans=t[0]*100+t[1]*10+t[2]
print(ans)
N=int(input())
NCount = 0
while N =>0:
    NCount+= 1
    N -=3
print(NCount-1)

### FIXED CODE ###

N=int(input())
NCount = 0
while N >=0:
    NCount+= 1
    N -=3
print(NCount-1)
b=input()

if b='A':
  print('T')
elif b='T':
  print('A')
elif b='G':
  print('C')
else:
  print('G')

### FIXED CODE ###

b=input()
 
if b=='A':
    print('T')
elif b=='T':
    print('A')
elif b=='G':
    print('C')
else:
    print('G')
N = input()
data = list(map(lambda x :int(x)%2,input().strip().split("")))
res = sum(data)
if res ==1:
  print(0)
else:
  data.sort()
  tmp = data[0]
  cnt = 0
  while tmp!=1:
    tmp/=2
    cnt+=1
  print(cnt)

### FIXED CODE ###

N = input()
data = list(map(lambda x :int(x),input().strip().split()))
data.sort()
tmp = data[0]
cnt =0
while tmp >1:
    if sum(list(map(lambda x:x%(2**(cnt+1)), data))) >= 1:break
    tmp//=2
    cnt+=1
print(cnt)
#! env python
# -*- coding: utf-8 -*-

import os
import sys

# at_coder.ABC086C_Traveling
# Date: 2019/06/02
# Filename: ABC086C_Traveling 

__author__ = 'acto_mini'
__date__ = "2019/06/02"


dict = [
    [1, 1, 0],
    [1, 0, 1],
    [1, -1, 0],
    [1, 0, -1]
]

def route (dis, current, goal):

    if dis < 0:
        return False

    new_current = [0, 0, 0]

    for d in dict:
        new_current[0] = current[0] + d[0]
        new_current[1] = current[1] + d[1]
        new_current[2] = current[2] + d[2]

        if goal[0] == new_current[0] and goal[1] == new_current[1] and goal[2] == new_current[2]:
            return True

        if route(dis-1, new_current, goal):
            return True

    return False

def main():
    # 作業ディレクトリを自身のファイルのディレクトリに変更
    os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))

    current = [0, 0, 0]

    # 整数の入力
    num = int(input())
    goal_list = []

    for i in range(num):
        t, x, y = map(int, input().split())
        goal_list.append([t, x, y])

    fail = False
    for i in range(num):

        t, x, y = goal_list[i][0], goal_list[i][1], goal_list[i][2]

        if route(dis=t, current=current, goal=[t, x, y]):
            current = [t, x, y]
            continue

        fail = True
        break

    if fail:
        print("NO")
    else:
        print("YES")

    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

#! env python
# -*- coding: utf-8 -*-

import os
import sys

# at_coder.ABC086C_Traveling
# Date: 2019/06/02
# Filename: ABC086C_Traveling 

__author__ = 'acto_mini'
__date__ = "2019/06/02"


def main():
    # 作業ディレクトリを自身のファイルのディレクトリに変更
    os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))

    t, x, y = [0], [0], [0]

    # 整数の入力
    num = int(input())

    for i in range(num):
        a, b, c = map(int, input().split())
        t.append(a)
        x.append(b)
        y.append(c)

    can = True
    for i in range(num):
        dt = t[i + 1] - t[i]
        dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
        if (dt < dist):
            can = False
        if (dt % 2 != dist % 2):
            can = False

    if can:
        print("Yes")
    else:
        print("No")

    return


if __name__ == '__main__':
    main()
import math
#数値ひとつ
I = int(input())
#数値欲しいとき
#N, M = map(int, input().split())
#文字欲しいとき
#N = input()
#それをListにしたいとき
#listA = list(N)
#受け取る数が未定かつリストにしたいとき
#list = list(map(int, input().split()))
#受け取る文字列が未定かつリストにしたいとき
list = '\n'.join(iter(input, ''))
print(len(set(list))-1)

### FIXED CODE ###

import math
#数値ひとつ
I = int(input())
#数値欲しいとき
#N, M = map(int, input().split())
#文字欲しいとき
#N = input()
#それをListにしたいとき
#listA = list(N)
#受け取る数が未定かつリストにしたいとき
#list = list(map(int, input().split()))
#受け取る文字列が未定かつリストにしたいとき(Iは回数)
list = [input() for i in range(I)]
print(len(set(list)))
def popularity(votes, N, M):
    
    total_votes = sum(votes)
    coef = 1.0 / (4.0 * M)
    limit = coef * total_votes
    
    cnt = 0
    for vote in votes:
        if vote > limit:
            cnt += 1
        if cnt >= M:
            return "Yes"
    
    return "No"
  
N, M = [int (x) for x in input().split()]
votes = [int (x) for x in input().split()]
print(popularity(votes, N, M))


### FIXED CODE ###

def swap(x,y,z):
  x, y = y, x
  x, z = z, x
  
  print('%d %d %d' % (x,y,z))
  
val = list(input().split(' '))
x, y, z = [ int(x) for x in val ]
swap(x,y,z)
#Contest with Drinks Easy
n=int(input())
t=list(map(int,input().split()))
m=int(input())
for i in range(m):
    a,b=map(int,input().split())
    total=t
    total[a]=b
    print(sum(total))

### FIXED CODE ###

import copy
n=int(input())
t=list(map(int,input().split()))
m=int(input())
for i in range(m):
    a,b=map(int,input().split())
    total=copy.copy(t)
    total[a-1]=b
    print(sum(total))
def a(t,x,y):
    n=abs(x)+abs(y)
    if (t-n)%2==0 and t-n>=0 :
        return 1
    else :
        return 0
N=int(input())
result=1
tn,xn,yn=0,0,0
for i in range(N):
    t,x,y=map(int,input().split())
    tn=t-tn
    xn=x-xn
    yn=y-yn
    result*=a(tn,xn,yn)
    print (result)
if result==1:
    print ('Yes')
else:
    print ('No')

### FIXED CODE ###

a,b=map(int,input().split())
if a*b%2 :
    print('Odd')
else:
    print('Even')
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 20 21:13:02 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A =[list(map(int,input().split())) for i in range(N)]

A.sort(key=lambda x: x[1])
kinds = 0
t = 0
for i in range(N):
    if t != A[i][0]:
        kinds += 1
        t = A[i][0]
c = K - kinds if K - kinds >=0 else 0
d = K-c
temp_t = pow(K-c,2)
i = N-1
counta =0
temp_d=0
a = [0 for i in range(N+1)]
b,b2 =[],[]
while counta < K:
    if c-a[A[i][0]] >= 0:
        temp_d += A[i][1]
        c = c-1 if a[A[i][0]] >= 1 else c
        a[A[i][0]] += 1
        counta+=1
        b2.append(A[i][1])
    else:
        b.append(A[i][1])
    i -=1
ans = temp_t+temp_d
#print(ans)
for i in range(len(b)):
    if b[i]-b2[-1-i]>pow(d,2)-pow(d-i-1,2):
        ans = ans +b[i]-b2[-1-i]-(pow(d,2)-pow(d-i-1,2))
    else:
        break
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Mon Jan 21 20:39:09 2019

@author: Yamazaki Kenichi
"""

N,K = map(int,input().split())
A = [list(map(int,input().split())) for i in range(N)]

A.sort(reverse = True,key=lambda x:x[1])
eat,noteat =[],[]
a = [0 for i in range(N+1)]
k = K
for i in range(N):
    if k != 0:
        if a[A[i][0]] ==0:
            a[A[i][0]] = 1
            eat.append(A[i][1])
            k -= 1
        else:
            noteat.append(A[i][1])
    else:
        noteat.append(A[i][1])
        
ans = [0 for i in range(min(K-k,len(noteat))+2)]
ans[0] = sum(eat)+ sum(noteat[:k])+ pow(K-k,2)

for i in range(1,min(K-k,len(noteat[k:])+1)):
    ans[i] = ans[i-1]-(pow(K-k-(i-1),2)+eat[-i]) +(pow(K-k-i,2)+noteat[k+i-1])

print(max(ans))
flags = {}
edges = {}

def dfs(next, before, distance):
    global flags, edges
    if next == 1:
        return
    elif flags[next][1] < distance:
        return
    else:
        flags[next][0] = before
        flags[next][1] = distance
        nexts_tmp = edges[next]
        for n in nexts_tmp:
            dfs(n, next, distance + 1)

def main():
    global flags, edges
    n, m = map(int, input().split())
    flags = {e:[0, n+1] for e in range(1, n + 1)}
    edges = {e:set() for e in range(1, n + 1)}
    for _ in range(m):
        a, b = map(int, input().split())
        edges[a].add(b)
        edges[b].add(a)

    next_from1 = edges[1]
    for n1 in next_from1:
        dfs(n1,1,1)
    result = [flags[f][1] < (n + 1) for f in flags if f > 1]
    if not all(result):
        print('No')
    else:
        print('Yes')
        for i1 in range(2, n + 1):
            print(flags[i1][0])


if __name__ == '__main__':
    main()

### FIXED CODE ###

from copy import deepcopy
def main():
    global flags, edges
    n, m = map(int, input().split())

    flags = {e:[n+1, n+1] for e in range(1, n + 1)}
    flags[1][1] = 0
    edges = {e:set() for e in range(1, n + 1)}
    edge_list = []
    for _ in range(m):
        a, b = map(int, input().split())
        edges[a].add(b)
        edges[b].add(a)
        edge_list.append((a, b))

    distance = 1
    node_next = list(edges[1])
    node_next_next = []
    while node_next:
        for next in node_next:
            if flags[next][1] > distance:
                flags[next][1] = distance
                node_next_next += edges[next]
        node_next = deepcopy(node_next_next)
        node_next_next = []
        distance += 1
    for edge in edge_list:
        e1 = edge[0]
        e2 = edge[1]
        if flags[e1][1] == flags[e2][1]:
            pass
        elif flags[e1][1] > flags[e2][1]:
            flags[e1][0] = min(flags[e1][0], e2)
        else:
            flags[e2][0] = min(flags[e2][0], e1)
    result = [flags[f][1] < (n + 1) for f in flags if f > 1]
    if not all(result):
        print('No')
    else:
        print('Yes')
        for i1 in range(2, n + 1):
            print(flags[i1][0])
            
if __name__ == '__main__':
    main()
import sys
n = int(input())
graph = {i:[] for i in range(n)}
for j in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n+1)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        res = 0
        for next_col in range(next_col_num):
            if _next == last:
                continue
            cnt += 1
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
n = int(input())
graph = {i:[] for i in range(n+1)}
for j in range(n-1):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    x -= 1
    y -= 1
    graph[x].append(y)
    graph[y].append(x)

memo_ls = [[None for j in range(2)] for i in range(n+1)]
# i番目の人がj色の時の通り数 0 : 白
cur = 0
def dfs(cur, col, last):
    if memo_ls[cur][col] is not None:
        return memo_ls[cur][col]
    next_col_num = 1 if col == 1 else 2
    _sum = 1
    cnt = 0
    for _next in graph[cur]:
        if _next == last:
            continue
        cnt += 1
        res = 0
        for next_col in range(next_col_num):
            res += dfs(_next, next_col, cur)
        _sum *= max(1, res)
    if cnt == 0:
        memo_ls[cur][col] = 1
        return 1
    res = _sum % (10 ** 9 + 7)
    memo_ls[cur][col] = res
    return res
res = dfs(0,0,-1) + dfs(0,1,-1)
print(res % (10**9+7))
n=int(input())
a = [int(input()) for _ in range(n)]
position = a.index(2) + 1
if position == False:
  print(-1)
  exit()
for i in range(n+1): # 最高でもn+!回だけ探してやれば十分
  position = a.index(position) + 1
  if position==1:
    print(i+2)
    exit()
print(-1)
exit()

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
pos=0
for i in range(n+1):
  if a[pos] == 2:
    print(i+1)
    exit()
  pos = a[pos]-1
print(-1)
n = int(input())
a = list(map(int,input().split()))

id = [0 for _ in range(n)]
for i in range(len(a)):
	id[a[i]-1] += 1

for i in id:
	print(i

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))

id = [0 for _ in range(n)]
for i in range(len(a)):
	id[a[i]-1] += 1

for i in id:
	print(i)
if a * b % == 1
 print(odd)
 else
 print(Even)

### FIXED CODE ###

a,b = map(int,input().split())
 
print("Even" if (a * b) % 2 == 0 else "Odd" )
NK=int(input())
ListNK=NK.split() #ListNK[0]=N,[1]=K
N=ListNK[0]
K=ListNK[1]
Listh=[]
ListQ=[]
for i in range(0,N,1):
  hi=int(input())
  Listh.append(hi)

Listh.sort() #Listhの要素を小さい順に並べる
for i in range(0,N-K+1,1):
  Q=int(Listh[K+i-1]-Listh[i]) #hmax-hminの候補.Qminを求めればよい
  ListQ.append(Q)
ListQ.sort()
print(ListQ[0])


### FIXED CODE ###

NK=input()
ListNK=NK.split() #ListNK[0]=N,[1]=K
N=int(ListNK[0])
K=int(ListNK[1])
Listh=[]
ListQ=[]
for i in range(0,N,1):
  hi=int(input())
  Listh.append(hi)

Listh.sort() #Listhの要素を小さい順に並べる
for i in range(0,N-K+1,1):
  Q=int(Listh[K+i-1]-Listh[i]) #hmax-hminの候補.Qminを求めればよい
  ListQ.append(Q)
ListQ.sort()
print(ListQ[0])
import sys

N, K = map(int, next(sys.stdin.buffer).split())
H = sorted(map(int, next(sys.stdin.buffer).split()))

print(sum(H[:K])

### FIXED CODE ###

import sys

N, K = map(int, next(sys.stdin.buffer).split())
H = list(map(int, next(sys.stdin.buffer).split()))

if K:
  H.sort()
  print(sum(H[:-K]))
else:
  print(sum(H))
N = input()
A = list(map(int, input().split))
tar = 1
for i in range(N):
    tar *= A[i]

print(tar)

### FIXED CODE ###


import sys
N = int(input())
A = list(map(int, input().split()))
A.sort()
tar = 1
for i in A:
    tar *= i
    if tar > 10 ** 18:
        print('-1')
        sys.exit()

print(tar)
import sys
 
n = int(input())
a = list(map(int, input().split()))
aa = [0] + [sum(A[:i + 1]) for i in range(N)] 
ans = sys.maxsize
 
def getdiff(left, center, right):
    return abs((aa[center] - aa[left]) - (aa[right] - aa[center]))
 
L = 1
R = 3
 
for C in range(2, n):
    while L + 1 < C and getdiff(0, L, C) > getdiff(0, L + 1, C):
        L += 1
    while R + 1 < n and getdiff(C, R, n) > getdiff(C, R + 1, n):
        R += 1
    pqrs = [aa[L], aa[C] - aa[L], aa[R] - aa[C], aa[n] - aa[R]]
    pqrs.sort()
    ans = min(ans, pqrs[3] - pqrs[0])
 
print(ans)


### FIXED CODE ###

import sys
 
n = int(input())
a = list(map(int, input().split()))
aa = [0]
for i in range(n):
    aa.append(aa[i] + a[i])
 
ans = sys.maxsize
 
def getdiff(left, center, right):
    return abs((aa[center] - aa[left]) - (aa[right] - aa[center]))
 
L = 1
R = 3
 
for C in range(2, n):
    while L + 1 < C and getdiff(0, L, C) > getdiff(0, L + 1, C):
        L += 1
    while R + 1 < n and getdiff(C, R, n) > getdiff(C, R + 1, n):
        R += 1
    pqrs = [aa[L], aa[C] - aa[L], aa[R] - aa[C], aa[n] - aa[R]]
    pqrs.sort()
    ans = min(ans, pqrs[3] - pqrs[0])
 
print(ans)
count,total = list(map(int,input().split()))
ret1 = -1
ret2 = -1
ret3 = -1
NF = True
if total <= count * 10000:
	for i in range(count + 1):
		rCount = count - i
		if total-10000*i <= rCount * 5000:
			for j in range(rCount + 1):
				if (i*10000 + j*5000 + (count-i-j)*1000) == total:
					ret1 = i
					ret2 = j
					ret3 = count-i-j
                    NF = False
				break
if NF:
  ret1 = -1
  ret2 = -1
  ret3 = -1
print(str(ret1) + " " + str(ret2) + " " + str(ret3))

### FIXED CODE ###

count,total = list(map(int,input().split()))
ret1 = -1
ret2 = -1
ret3 = -1
NF = True
if total <= count * 10000:
	for i in range(count + 1):
		rCount = count - i
		if total-10000*i <= rCount * 5000:
			for j in range(rCount + 1):
				if (i*10000 + j*5000 + (count-i-j)*1000) == total:
					ret1 = i
					ret2 = j
					ret3 = count-i-j
					NF = False
					break
if NF:
	ret1 = -1
	ret2 = -1
	ret3 = -1
print(str(ret1) + " " + str(ret2) + " " + str(ret3))
K = int(input())
s = "
for i in range(K):
  s += "ACL"
print(s)

### FIXED CODE ###

K = int(input())
s = ""
for i in range(K):
  s += "ACL"
print(s)
S = input()
week = ["SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"]
for i in week:
  if week[i] == S:
    print(7 - i)

### FIXED CODE ###

S = input()
week = ["SUN","MON", "TUE", "WED", "THU", "FRI", "SAT"]
for i in range(7):
  if week[i] == S:
    print(7 - i)
n = int(input)
a = int(input)
print("Yes") if n % 500 < a else print("No")

### FIXED CODE ###

n = int(input())
a = int(input())
print("Yes") if n % 500 <= a else print("No")
import math
import sys


def dudge_answer(a, b):
    ave = (a+b)/2
    return math.ceil(ave)


print(dudge_answer(sys.argv[1], sys.argv[2]))


### FIXED CODE ###

a, b = map(int, input().split())
print((a + b + 1) // 2)
n = input()
print((1000 - n % 1000) % 1000)

### FIXED CODE ###

n = int(input())
print((1000 - n % 1000) % 1000)