Harryxun/stf_run huggingface dataset:
X,N=map(int,input().split())
n=list(map(int,input().split()))
if X<min(n) or X>max(n):
  print(X)
  exit()

key=min(n)-1
Key=max(n)+1
l=list(range(key,Key+1))
ll=[x for x in l if x not in n]
ll.append(X)
ll.sort()
i=ll.index(X)
if abs(X-ll[i-1])>abs(X-ll[i+1]):
  print(ll[i+1])
else:
  print(ll[i-1])

  

### FIXED CODE ###

X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
n=list(map(int,input().split()))
if X<min(n) or X>max(n):
  print(X)
  exit()

key=min(n)-1
Key=max(n)+1
l=list(range(key,Key+1))
ll=[x for x in l if x not in n]
ll.append(X)
ll.sort()
i=ll.index(X)
if abs(X-ll[i-1])>abs(X-ll[i+1]):
  print(ll[i+1])
else:
  print(ll[i-1])
import sys
input = sys.stdin.readline

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

da = [[] for i in range(a)]
d = []
for i in range(b):
    k,kk = map(int,input().split())
    da[k-1].append(kk)
    d.append([k, kk])


da.sort()

for i in d:
    p = da[i[0]-1].index(i[1])

    n = str(i[0])
    m = str(p+1)

    n = "0"*(6-len(n)) + n
    m = "0"*(6-len(m)) + m

    print(n+m)

### FIXED CODE ###

import sys
input = sys.stdin.readline

a,b = map(int,input().split())
aa = []
d = []
for i in range(b):
    k,kk = map(int,input().split())
    d.append([k, kk,i+1])

da = sorted(d)

kkk = da[0][0]
ll = 0
for i in range(b):
    kkkk = da[i][0]
    if kkk == kkkk:
        ll += 1
    else:
        kkk = kkkk
        ll = 1
    aa.append([da[i][2],da[i][0],ll])
aa.sort()

for i in aa:
    m = str(i[1])
    n = str(i[2])
    m = "0"*(6-len(m))+m
    n = "0"*(6-len(n))+n
    print(m+n)
n, m = map(int, input().split())
S, C = [], []
for _ in range(m):
  s, c = map(int, input().split())
  S.append(s)
  C.append(c)
  
for num in range(10 ** (max(S) - 1), 10 ** n):
  num = str(num)
  f = 1
  for s, c in zip(S, C):
    s = s - 1
    if int(num[s]) != c:
      f = 0
      break
      
  if f:
    ans = num
    break
    
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
 
num = [-1] * n
ans = -1
f = 1
 
for _ in range(m):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    if n == 1:
      ans = 0
    f = 0
    break
    
  i = num[s - 1]
  if i == -1:
    num[s-1] = c
  elif i == c:
    continue
  else:
    f = 0
    break
  
if num[0] == -1:
  if n == 1:
    num[0] = 0
  else:
    num[0] = 1
  
if f:
  num = [0 if n == -1 else n for n in num]
  ans = ''.join(map(str, num))
  
print(ans)
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
while b[j] > K - a[i]:
    j -= 1
ans = max(ans, i + j)
print(ans)

### FIXED CODE ###

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

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)
first_line = input()
N, Q = first_line.split(' ')
N = int(N) #length of the input sentence
Q = int(Q) #num of the questions

S = input() #input sentence

numbers_of_AC = []

question_atributes = []
for _ in range(Q):
    start, end = (input().split(' '))
    start = int(start)
    end = int(end)
    
    for c in S:
		if c == 'A':
			count+=1
		else:
			numbers_of_AC.append(count)
    		count = 0
	numbers_of_AC.append(count)

    

### FIXED CODE ###

b = input()
if b=='A':
  print ('T')
elif b=='T':
  print ('A')
elif b=='C':
  print ('G')
elif b=='G':
  print ('C')
n=input()
if a[2]==a[3] and a[4]==a[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=input()
if a[2]==a[3] and a[4]==a[5]:
  print("Yes")
else:
  print("No")
import math


def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    mul = a[0]
    for i in range(1, n):
        mul = mul * a[i] // math.gcd(mul, a[i])
    if m > mul // 2:
        ans = (m - mul // 2) // mul + 1
        print(int(ans))
    else:
        print(0)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def div_ceil(x, y): return (x + y - 1) // y
 
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
    L *= a // gcd(L, a)
for a in A:
    if (L // a) % 2 == 0:
        ans = 0
        break
else:
    ans = div_ceil(M // L, 2)
print(ans)
n=int(input())
l=list(map(int,input().split()))

l.sort()


print(cnt)


### FIXED CODE ###

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

l.sort()
l.append(10**9)
cnt=0
i=0
#print(l)

while i<n-2:
    j=i+1
    while j<n-1:
        LL=j+1
        RR=n-1
        #print("#",l[i],l[j],l[LL],l[RR])
        while LL<=RR:
            k=(LL+RR)//2
            if k==n:
                break
            #print(l)
            #print(i,j,LL,RR,k)
            #print(l[i]+l[j],l[k],l[k+1])
            if l[i]+l[j]>l[k] and l[i]+l[j]<=l[k+1]:
                cnt+=k-j
                break
            elif LL==RR:
                break
            elif l[i]+l[j]<=l[k]:
                RR=k
            elif l[i]+l[j]>l[k]:
                LL=k+1
            elif l[i]+l[j]<l[k] and k==j+1:
                break
        j+=1
    i+=1

print(cnt)
a, b, c = input()

if len(set([a, b, c])) == 2:
  print("yes")
else:
  print("No")

### FIXED CODE ###

a, b, c = input().split()
 
if len(set([a, b, c])) == 2:
  print("Yes")
else:
  print("No")
N = int(input())
Bs = list(map(int, input().split()))
 
As = [ None for _ in range(N) ]

As[0] = Bs[0]
for i in range(1, N):  
  As[i] = min(Bs[i-1], Bs[i])

print(sum(As))

### FIXED CODE ###

N = int(input())
Bs = list(map(int, input().split()))
 
As = [ None for _ in range(N) ]

As[0] = Bs[0]
for i in range(1, N-1):  
  As[i] = min(Bs[i-1], Bs[i])

As[-1] = Bs[-1]

print(sum(As))
a=list(input().split())
if a[0]==9 or a[1]==9:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=list(input())
if a[0]!="9" and a[1]!="9":
  print("No")
else:
  print("Yes")
import math
N,D = map(int,input().split())

people = math.ceil(N // (2D+1))
print(people)

### FIXED CODE ###

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

people = N / (2*D+1)
if people % 1.0 != 0:#割り切れないのであれば？？
    people+=1
print(int(people))
import numpy as np
N = int(input())
P = np.array(list(map(int,input().split())))*2
A = np.array([np.zeros(N)]*N)

for i in range(N):
    if i == 0:
        A[0][0] = 1
        A[-1][0] = 1
    else:
        A[i-1][i] = 1
        A[i][i] = 1
        
ans = [int(round(one,0)) for one in np.dot(np.linalg.pinv(A),P)]

ans_s = ""
for one in ans:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)

### FIXED CODE ###

import numpy as np
N = int(input())
p = np.array(list(map(int,input().split())))
a0 = 0
for i in range(0,N,2):
    a0 += p[i]
    
for i in range(1,N-1,2):
    a0 -= p[i]
    
ans2 = [a0]*N
# iは-1している(slice)ので、+1しないといけないことに注意
for i,one in enumerate(p[1:]):
    ans2[i+1] = 2*p[i] - ans2[i] 
    
ans_s = ""
for one in ans2:
    ans_s += "{} ".format(one)
ans_s = ans_s[:-1]

print(ans_s)
import numpy as np

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

x=[]
for i in range(n):
    x.append(np.array(list(map(int,input().split()))))

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        if np.linalg.norm(x[i]-x[j]) % 1 == 0.0:
#            print(np.linalg.norm(x[i]-x[j]))
            ans+=1





print(ans)

### FIXED CODE ###

import math

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

x=[]
for i in range(n):
    x.append(list(map(int,input().split())))

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        nor = math.sqrt(sum([(x[i][k]-x[j][k])**2 for k in range(d)]))
        
        if nor.is_integer():
#            print(nor)
            ans+=1

print(ans)
stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in set(A):
    d[i]=A.count(i)
    ans+=d[i]*(d[i]-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)

### FIXED CODE ###

stdin =open(0).read().split('\n')
N=int(stdin[0])
A=list(map(int,stdin[1].split()))
from collections import Counter
C=Counter(A)
ans=0
for i in C.values():
    ans+=i*(i-1)//2
for a in A:
    num = C[a]
    print(ans-num*(num-1)//2+(num-1)*(num-2)//2)
n,k=(int(i) for i in input().split())
h=[]
for i in input().split():
  h.append(int(i))
h.sort()
for i in range(k):
  h.pop(-1)
print(sum(h)+k)

### FIXED CODE ###

n,k=(int(i) for i in input().split())
h=[]
for i in input().split():
  h.append(int(i))
h.sort()
if k!=0:
	for i in range(min(n,k)):
 	  h.pop(-1)
print(sum(h))
n = int(input())
*h, = map(int, input().split())

def rec(i: int, c: int) -> int:
    if i <= 0:
        return c
    elif i == 1:
        return rec(i-1, c+abs(h[i]-h[i-1]))

    return min(rec(i-1, c+abs(h[i]-h[i-1])), rec(i-2, c+abs(h[i]-h[i-2])))

print(rec(n-1, 0))


### FIXED CODE ###

n = int(input())
*h, = map(int, input().split())

dp = [float("inf")]*(n+1)
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]), dp[i])
    if i > 1:
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i])

print(dp[n-1])
n = int(input())
al = list(map(int, input().split()))
ans = []
for i in range(1, n+1):
    print(index(i) + 1)

### FIXED CODE ###

n = int(input())
al = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[al[i] - 1] = i + 1
print(*ans)
import sys
input = sys.stdin.readline

# D - Moving Piece
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

# 問題文とインデックスの位置を揃える
P.insert(0, 0)
C.insert(0, 0)

# マス目を周期ごとに分割する
groups = []
appeared = set()

for i in range(1, N + 1):
	if not i in appeared:
		group = []
		s = set()
		j = i

		while not j in s:
			group.append(j)
			s.add(j)
			appeared.add(j)
			j = P[j]

		groups.append(group)

ans = -sys.maxsize

# 周期ごとにハイスコアを算出
for group in groups:
	# スタート位置を1マスずつズラす
	for g in group:
		score = 0
		max_score = -sys.maxsize
		scores = []
		scores.append(-sys.maxsize)
		Pi = P[g]

		for j in range(len(group)):
			score += C[Pi]
			max_score = max(max_score, score)
			scores.append(max_score)
			Pi = P[Pi]

		if K > N and score > 0:
			s = scores[K % len(group)] + score * (K // len(group))
			ans = max(ans, s)
		elif K > N:
			ans = max(ans, max_score)
		else:
			ans = max(ans, scores[K])

print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline

# D - Moving Piece
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

# 問題文とインデックスの位置を揃える
P.insert(0, 0)
C.insert(0, 0)

# マス目を周期ごとに分割する
groups = []
appeared = set()

for i in range(1, N + 1):
	if not i in appeared:
		group = []
		s = set()
		j = i

		while not j in s:
			group.append(j)
			s.add(j)
			appeared.add(j)
			j = P[j]

		groups.append(group)

MIN = -sys.maxsize
ans = MIN

# 周期ごとにハイスコアを算出
for group in groups:
	n = len(group)

	# スタート位置を1マスずつズラす
	for g in group:
		score = 0
		max_score = MIN
		scores = []
		scores.append(MIN)
		Pi = P[g]

		for j in range(n):
			score += C[Pi]
			max_score = max(max_score, score)
			scores.append(max_score)
			Pi = P[Pi]

		if K > n and score > 0:
			s = scores[K % n] + score * (K // n)
			ans = max(ans, s)

			s = max_score + score * (K // n - 1)
			ans = max(ans, s)
		elif K > n:
			ans = max(ans, max_score)
		else:
			ans = max(ans, scores[K])

print(ans)
N,M,T=map(int,input().split())
print((N//X)*T+1)

### FIXED CODE ###

N,X,T=map(int,input().split())
if N%X==0:
  print((N//X)*T)
else:
  print(((N//X)*T)+T)
a = int(input())
b = int(input())
c = int(input())
print(((a + b) * h) // 2)

### FIXED CODE ###

a = int(input())
b = int(input())
c = int(input())
print(((a + b) * c) // 2)
import queue

H, W = list(map(int, input().split()))
s = [list(input()) + ['#'] for i in range(H)] + [['#' for i in range(W+1)]]
white = sum([s[i].count('.') for i in range(H)])

q = queue.PriorityQueue()
s[0][0] = 1
q.put((0,0))

while not q.empty():
    i, j = q.get()
    for x, y in [(i+1,j), (i-1,j), (i,j+1), (i,j-1)]:
        if s[x][y] == '.':
            s[x][y] = s[i][j]+1
            q.put((x, y))

print(white-s[H-1][W-1])

### FIXED CODE ###

import queue

H, W = list(map(int, input().split()))
s = [list(input()) + ['#'] for i in range(H)] + [['#' for i in range(W+1)]]
white = sum([s[i].count('.') for i in range(H)])

q = queue.Queue()
s[0][0] = 1
q.put((0,0))

while not q.empty():
    i, j = q.get()
    for x, y in [(i+1,j), (i-1,j), (i,j+1), (i,j-1)]:
        if s[x][y] == '.':
            s[x][y] = s[i][j]+1
            q.put((x, y))

if s[H-1][W-1] in ['.', '#']:
    print(-1)
else:
    print(white-s[H-1][W-1])
N, D = map(int, input())

# pts = [tuple(map(int, input())) for _ in range(N)]

ans = 0
if _ in range(N):
  x, y = map(int, input())
  if x**2 + y**2 <= D**2:
    ans+=1
    
print(ans)
  

### FIXED CODE ###

N, D = map(int, input().split(' '))

# pts = [tuple(map(int, input())) for _ in range(N)]

ans = 0
for _ in range(N):
  x, y = map(int, input().split(' '))
  if x**2 + y**2 <= D**2:
    ans+=1
    
print(ans)
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = sorted(LI())
F = sorted(LI(), reverse=True)


que = [(-A[i] * F[i], -F[i], A[i]) for i in range(n)]
heapify(que)
while k and que:
    x, f, a = heappop(que)
    if a:
        a -= 1
        x -= f
        heappush(que, (x, f, a))
        k -= 1



print(-min([que[i][0] for i in range(len(que))]))


### FIXED CODE ###

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, atan2, degrees
from operator import mul
from functools import reduce
sys.setrecursionlimit(10**8)

INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = sorted(LI())
F = sorted(LI(), reverse=True)
ok = A[-1] * F[0]
ng = -1
while ok > ng + 1:
    mid = (ok + ng) // 2
    ret = 0
    for i in range(n):
        if A[i] * F[i] > mid:
            ret += (A[i] * F[i] - mid) // F[i] + bool((A[i] * F[i] - mid) % F[i])
    if ret > k:
        ng = mid
    else:
        ok = mid


print(ok)
import numpy as np

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

A_inv = 1 / A
print(1 / np.sum(A_inv))


### FIXED CODE ###

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

inv_sum = 0
for a in A:
    inv_sum += 1 / a

print(1 / inv_sum)
s = input()
a = int(s)%2019
mod_N = [0]*2019
mod_N[a] += 1
r = 10**(len(s)-1)
for i in s:
  a = (a-int(i)*10**d)%2019
  d = d//10
  mod_N[a] += 1
ans = 0
for i in mod_N:
  ans += i*(i-1)//2
print(ans)

### FIXED CODE ###

s = input()
a = 0
mods = [0]*2019
mods[a] += 1
r = 1
for i in s[::-1]:
  a = (a+int(i)*r)%2019
  r = r*10%2019
  mods[a] += 1
ans = 0
for i in mods:
  ans += i*(i-1)//2
print(ans)
N,T = map(int,input().split())
food = list(list(map(int,input().split()))for i in range(N))
DP = [[0]*(T) for i in range(N+1)]
for i in range(N):
    a,b = food[i]
    for j in range(a):
        DP[i+1][j] = DP[i][j]
    for j in range(a,T):
        DP[i+1][j] = max(DP[i][j],DP[i][j-a]+b)
ans = 0
i = N
j = T-1
while i > 0 and j > 0:
    if DP[i][j] == DP[i][j-1]:
        j -= 1
    elif DP[i][j] == DP[i-1][j]:
        i -= 1
    else:
        food[i-1][1] = 0
        i -= 1
        j -= food[i][0]
food.sort(reverse=True,key= lambda x:x[1])
print(DP[-1][-1]+food[0][1])

### FIXED CODE ###

N,T = map(int,input().split())
food = list(list(map(int,input().split()))for i in range(N))
DP = [[0]*(T) for i in range(N+1)]
for i in range(N):
    a,b = food[i]
    for j in range(min(a,T)):
        DP[i+1][j] = DP[i][j]
    for j in range(a,T):
        DP[i+1][j] = max(DP[i][j],DP[i][j-a]+b)
ans = 0
i = N
j = T-1
while i > 0 and j > 0:
    if DP[i][j] == DP[i][j-1]:
        j -= 1
    elif DP[i][j] == DP[i-1][j]:
        i -= 1
    else:
        food[i-1][1] = 0
        j -= food[i-1][0]
        i -= 1
food.sort(reverse=True,key= lambda x:x[1])
print(DP[-1][-1]+food[0][1])
a=str(input())
b=str(input())
c=str(input())
x=a[1]
a=a[1:]
while True:
  if x=='a':
    x=a[1]
    a=a[1:]
    if len(a)==0:
      print("A")
      break
  elif x=='b':
    x=b[1]
    b=b[1:]
    if len(b)==0:
      print("B")
      break
  else:
    x=c[1]
    c=c[1:]
    if len(c)==0:
      print("C")
      break

### FIXED CODE ###

s = {'a': input(), 'b': input(), 'c': input()}
 
now = 'a'
while s[now] != '':
    next = s[now][0]
    s[now] = s[now][1:]
    now = next
print(now.upper())
#0が1をスペース区切りで3つ入力
a, b, c = map(int, input().split())

#aからcそれぞれが1と等しいかどうかを判断し、等しいのであれば順次iに1を足していく
i = 0

#aについて
if a==1:
    i += 1
    
#bについて
if b==1:
    i += 1    

#cについて
if c==1:
    i += 1
    
#出力
print(i)

### FIXED CODE ###

#0が1を3つ入力
a, b, c = map(int, input())

#aからcそれぞれが1と等しいかどうかを判断し、等しいのであれば順次iに1を足していく
i = 0

#aについて
if a==1:
    i += 1
    
#bについて
if b==1:
    i += 1    

#cについて
if c==1:
    i += 1
    
#出力
print(i)
from collections import deque
s = input()
a = deque()
for i in s:
    if i == "B":
        a.pop()
    else:
        a.append(i)
print(''.join(a))

### FIXED CODE ###

S = str(input())
st = ""
for i in range(len(S)):
    if S[i] == "1":
        st += "1"
    elif S[i] =="0":
        st += "0"
    else:
        st = st[:-1]
print(st)
N = int(input())
H = list(map(int, input().split()))
ans = []
a = 0

for i in range(N-2):
    if H[t] >= H[t+1]:
        a += 1
    else:
        a = 0
    ans.append(a)
    
print(max(ans))


### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
ans = []
a = 0

if N == 1:
    print('0')
    exit()

for i in range(N-1):
    if H[i] >= H[i+1]:
        a += 1
    else:
        a = 0
    ans.append(a)

print(max(ans))
import collections


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

if len(set(l)) == 1:
    print(n//2)
    exit()

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]
ce = collections.Counter(leven)
co = collections.Counter(lodd)

ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != ce[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - ce[-1][1])
else:
    print(n - ce[-1][1] - ce[-2][1])


### FIXED CODE ###

import collections


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

if len(set(l)) == 1:
    print(n//2)
    exit()

leven = [x for x in l[::2]]
lodd  = [x for x in l[1::2]]

ce = collections.Counter(leven)
co = collections.Counter(lodd)
ce = sorted(ce.items(), key=lambda x:x[1])
co = sorted(co.items(), key=lambda x:x[1])

if ce[-1][0] != co[-1][0]:
	print(n - ce[-1][1] - co[-1][1])
elif ce[-2][1] > co[-2][1]:
    print(n - ce[-2][1] - co[-1][1])
else:
    print(n - ce[-1][1] - co[-2][1])
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = [map(int, input().split()) for _ in range(m)]

bc.sort(reverse=True, key=lambda x:x[1])

i = 0
for b,c in bc:
    for j in range(i, min(n, i+b)):
        if a[j]<c:
            a[j] = c
    i = i+b
print(sum(a))


### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
bc = [list(map(int, input().split())) for _ in range(m)]

bc.sort(reverse=True, key=lambda x:x[1])

i = 0
for b,c in bc:
    for j in range(i, min(n, i+b)):
        if a[j]<c:
            a[j] = c
    i = i+b
print(sum(a))
n,m = map(int, input().split())
sc= [map(int, input().split()) for _ in range(m)]
s, c = [list(i) for i in zip(*sc)]

ans = 10001
for i in range(m):
    tmp = 0
    if s[i] == 0:
        tmp += 1
    elif tmp == m:
        print(0)

for l in range((10**(n-1)),10**n):
    ln = str(l)


    tmp = 0
    for j in range(m):
        if int(ln[int(s[j])-1]) == int(c[j]):
            tmp += 1
            # print(tmp)
            if tmp == m:
                ans = int(ln)
                print(ans)
                break

        else:
            # print(tmp)
            break
    if ans != 10001:
        break

if ans == 10001:
    print(-1)


### FIXED CODE ###

# n,m = map(int, input().split())
# sc = [map(int, input().split()) for _ in range(m)]
# s, c = [list(i) for i in zip(*sc)]
#
#
#
# for i in range(10**n):
#     ans = str(i)
#     if len(i) == n and all([i[s[j]-1] == str(c[j]) for j in range(m)]):
#         print(ans)
#         exit()
#
#
# print(-1)

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

s, c = [], []
for _ in range(m):
    s_, c_ = map(int, input().split())
    s.append(s_)
    c.append(c_)

for i in range(10 ** n):
    ans = str(i)
    if len(ans) == n and all([ans[s[j] - 1] == str(c[j]) for j in range(m)]):
        print(ans)
        exit()

print(-1)