Harryxun/stf_run huggingface dataset:
from collections import deque
import heapq
def makeTree(i):
    V = [(A[i],i)]
    que = deque([i])
    hist[i] = 1
    while que:
        x = que.popleft()
        for y in G[x]:
            if hist[y]==0:
                heapq.heappush(V,(A[y],y))
                que.append(y)
                hist[y] = 1
    T[i] = V
N,M = map(int,input().split())
A = list(map(int,input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x,y = map(int,input().split())
    G[x].append(y)
    G[y].append(x)
T = {}
hist = [0 for _ in range(N)]
for i in range(N):
    if hist[i]==0:
        makeTree(i)
if N<2*(len(T)-1):
    print("Impossible")
else:
    heap = []
    for t in T:
        c,v = heapq.heappop(T[t])
        heapq.heappush(heap,(c,v,t))
    cnt = 0
    while len(heap)>=2:
        c1,v1,t1 = heapq.heappop(heap)
        c2,v2,t2 = heapq.heappop(heap)
        cnt += c1+c2
        if len(T[t1])>=len(T[t2]):
            while T[t2]:
                heapq.heappush(T[t1],heapq.heappop(T[t2]))
            del T[t2]
            c3,v3 = heapq.heappop(T[t1])
            heapq.heappush(heap,(c3,v3,t1))
        else:
            while T[t1]:
                heapq.heappush(T[t2],heapq.heappop(T[t1]))
            del T[t1]
            c3,v3 = heapq.heappop(T[t2])
            heapq.heappush(heap,(c3,v3,t2))
    print(cnt)

### FIXED CODE ###

from collections import deque
import heapq
N,M = map(int,input().split())
A = list(map(int,input().split()))
G = {i:[] for i in range(N)}
for _ in range(M):
    x,y = map(int,input().split())
    G[x].append(y)
    G[y].append(x)
F = []
hist = [0 for _ in range(N)]
for i in range(N):
    T = []
    if hist[i]==0:
        que = deque([i])
        hist[i]=1
        heapq.heappush(T,A[i])
        while que:
            x = que.popleft()
            for y in G[x]:
                if hist[y]==0:
                    que.append(y)
                    hist[y]=1
                    heapq.heappush(T,A[y])
        F.append(T)
K = len(F)
if K>N//2+1:        
    cnt = -1
elif K==1:
    cnt = 0
else:
    cnt = 0
    for i in range(K):
        cnt += heapq.heappop(F[i])
    F1 = []
    for T in F:
        F1 += T
    F1 = sorted(F1)
    for i in range(K-2):
        cnt += F1[i]
if cnt<0:
    print("Impossible")
else:
    print(cnt)
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def input():
    return sys.stdin.readline().strip()


def _main():
	input()
    s = sorted(list(input().split()))
    print("".join(s))


if __name__ == "__main__":
    _main()


### FIXED CODE ###

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def input():
    return sys.stdin.readline().strip()


def _main():
    n, length = get_ints()
    s_list = [""] * n
    for i in range(n):
        s_list[i] = input()
    s = sorted(s_list)
    print("".join(s))


if __name__ == "__main__":
    _main()
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
count = 0
ans = []
for i in range(n):
  for j in range(n-1):
    if j >= i and a[j]-a[i] <= 2:
      #print(i,j)
      count += 1
    else:
      ans.append(count)
      count = 0
if n == 1:
  print(1)
else:
  print(max(ans))

### FIXED CODE ###

s = list(input())
a = []
for i in range(len(s)):
  if 2*i+1 <= len(s):
    a.append(s[2*i])
  else:
    break
print(''.join(a))
A,B,K = map(int,input().split())
x = []
if A >= B:
  for i in range(1,A):
    if A % i == 0 and B % i == 0:
      x.append(i)
else:
  for i in range(1,B):
    if A % i == 0 and B % i == 0:
      x.append(i)
x.sort(reverse=True)
print(x[K - 1])
  

### FIXED CODE ###

a, b, k = map(int, input().split())
print([i for i in range(1,101) if a%i+b%i<1][-k])
S = input();

if S[3]==S[4] & S[5]==S[6]:
  print("Yes");
else
  print("No");

### FIXED CODE ###

S = input();
 
if S[2]==S[3] and S[4]==S[5]:
  print("Yes");
else:
  print("No");
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect


if __name__ == "__main__":
    n = int(input())
    ans = [0]*(n**5)
    for i in range(1,int(n**0.5)+1):
        for j in range(1,int(n**0.5)+1):
            for k in range(1,int(n**0.5)+1):
                ans[i**2 + j**2 + k**2 + i*j + j*k + i*k]+=1
    for i in range(1,n+1):
        print(ans[i])

### FIXED CODE ###

import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect


if __name__ == "__main__":
    n = int(input())
    ans = [0]*(n+1)
    for i in range(1,int(n**0.5)+1):
        for j in range(1,int(n**0.5)+1):
            for k in range(1,int(n**0.5)+1):
                if i**2 + j**2 + k**2 + i*j + j*k + i*k<=n:
                    ans[i**2 + j**2 + k**2 + i*j + j*k + i*k]+=1
    for i in range(1,n+1):
        print(ans[i])
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
input()
u = set()
i = None
for x in map(int, input().split()):
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
  i = (i or s) & s
print(('not' if i else r) + ' coprime')


### FIXED CODE ###

N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
n = int(input())
a = [int(x) for x in input().split() if x > '1']
if len(a) > 1:
  u = set()
  i = None
  for x in a:
    s = set()
    while x > 1:
      p = spf[x]
      if p in u:
        r = 'setwise'
      s.add(p)
      x //= p
    u |= s
    if len(a) == n:
      if i is None: i = s
      else: i &= s
  if i:
    r = 'not'
print(r, 'coprime')
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from math import gcd
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        N = int(input())
        A = list(map(int, input().split()))

        if all(a == 0 for a in A):
            return True
        if N % 3 != 0:
            return False

        AA = Counter(A)
        if len(AA) == 2:
            AAA = AA.most_common()
            for k, v in AAA.items():
                if v != N * 2 // 3:
                    return False
            return AAA[1][0] == 0

        if len(AA) == 3:
            if any(v != N // 3 for v in AA.values()):
                return False
            k1, k2, k3 = AA.keys()
            return k1 ^ k2 == k3 or k1 ^ k3 == k2 or k2 ^ k3 == k1

    print('Yes' if main() else 'No')


resolve()

### FIXED CODE ###

# import bisect
from collections import Counter, deque  # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from math import gcd
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        N = int(input())
        A = list(map(int, input().split()))

        if all(a == 0 for a in A):
            return True
        if N % 3 != 0:
            return False

        AA = Counter(A)
        if len(AA) == 2:
            AAA = AA.most_common()
            if AAA[0][1] != N * 2 // 3:
                return False
            return AAA[1][0] == 0

        if len(AA) == 3:
            if any(v != N // 3 for v in AA.values()):
                return False
            k1, k2, k3 = AA.keys()
            return k1 ^ k2 == k3 or k1 ^ k3 == k2 or k2 ^ k3 == k1

    print('Yes' if main() else 'No')


resolve()
import math
a, b = map(int, input().split())

print((a * b) // math.gcd(a,b))

### FIXED CODE ###

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

print((a * b) // fractions.gcd(a,b))
X,Y,A,B,C  = map(int, input().split())
ps = sorted(list(map(int, input().split())),reverse=True)
qs = sorted(list(map(int, input().split())),reverse=True)
# qs = list(map(int, input().split()))
rs = sorted(list(map(int, input().split())),reverse=True)

# cnt_x = 0
# cnt_y = 0
ps = ps[:X]
qs = qs[:Y]
cnt_c = 0
ans = sum(ps)+sum(qs)
while cnt_c < C:
    p = ps.pop()
    q = qs.pop()
    r = rs[cnt_c]
    if p - r >= 0 and q - r >= 0:
        break
    elif r - p > r - q: #pのほうが差分が大きい
        qs.append(q)
        ans -= p
        ans += r
    else:
        ps.append(p)
        ans -= q
        ans += r
    cnt_c += 1
print(ans)





### FIXED CODE ###

X,Y,A,B,C  = map(int, input().split())
ps = sorted(list(map(int, input().split())),reverse=True)
qs = sorted(list(map(int, input().split())),reverse=True)
rs = sorted(list(map(int, input().split())),reverse=True)

ps = ps[:X]
qs = qs[:Y]
cnt_c = 0
ans = sum(ps)+sum(qs)
INF = 10**10
while cnt_c < C:
    if len(ps) != 0:
        p = ps.pop()
    else:
        p = INF
    if len(qs) != 0:
        q = qs.pop()
    else:
        q = INF
    r = rs[cnt_c]
    if p - r >= 0 and q - r >= 0:
        break
    elif r - p > r - q: #pのほうが差分が大きい
        qs.append(q)
        ans -= p
        ans += r
    else:
        ps.append(p)
        ans -= q
        ans += r
    cnt_c += 1
print(ans)



"""
2 2 2 2 4
2 4
5 1
10 10 10 10 10
"""
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
A_ = []
A_1 = [i for i in A]
A_1 = [i%A[0] for i in A_1]
A_2 = [2*i for i in A]
A_2 = [i%A[0] for i in A_2]
A_3 = [i for i in A]
A_3 = [i%(A[1]-A[0]) for i in A_3]
A_ = A_1 + A_2 + A_3 
A_ = sorted(set(A_))
if A_ == [0]*len(A_):
  print(A[0])
else:
  print(A_[1])

### FIXED CODE ###

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

A_tmp=A[0]
for i in A[1:]:
  if i%A_tmp != 0:
    A_tmp = i%A_tmp
    
while(1):
  tmp = [x%A_tmp for x in A if x%A_tmp != 0]
  if sum(tmp) != 0:
    A_tmp = min(tmp)
  else:
    break
print(A_tmp)
S = input()
T = ''

def Tcmp(T, moji):
	T += moji
	
	if (S == T):
		return 1
	if len(T) > len(S):
		return 0
	
	if (moji == "dream"):
		return max(Tcmp(T,""),Tcmp(T,"er"))
	elif(moji == "eras"):
		return max(Tcmp(T,"e"),Tcmp(T,"er"))
	else:
		return max(Tcmp(T,"dream"),Tcmp(T,"eras"))

if(Tcmp(T,"")):
	print("YES")
else:
	print("NO")


### FIXED CODE ###

#ABC 049 C
S = input()
T = ''
S = S[::-1]
words = ["dream","dreamer","erase","eraser"]
rev_words = [w[::-1] for w in words]

flag = False
i=0
while(1):
	for w in rev_words:
		s = S[i:i+len(w)]
		if s == w:
			flag = True
			T += w
			i += len(w)
			break
	if T == S:
		ans = "YES"
		break
	if flag == False:
		ans = 'NO'
		break
	flag = False

print(ans)
from decimal import Decimal

a,b = input().split()
b = round(b*100)
c = int(a)*int(b)//100

print(c)

### FIXED CODE ###

from decimal import Decimal

a,b = input().split()
b = b.replace(".","")
c = int(a)*int(b)//100

print(c)
import collections

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

c = list(collections.Counter(A).items())
c.sort(reverse=True)

a = 0

for i in range(N):
    if c[i][1] >= 4:
        a = c[i][0]
        b = c[i][0]
        break
    elif c[i][1] >= 2:
        a = c[i][0]
        e = i
        break

b = 0

if a == 0:
    print(0)
else:
    for i in range(e+1, N):
        if c[i][1] >= 2:
            b = c[i][0]
            break
    if b == 0:
        print(0)
    else:
        print(a*b)




### FIXED CODE ###

import collections

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

c = list(collections.Counter(A).items())
c.sort(reverse=True)

a = 0
b = 0
e = -1

for i in range(N):
    if c[i][1] >= 4:
        a = c[i][0]
        b = c[i][0]
        break
    elif c[i][1] >= 2:
        a = c[i][0]
        e = i
        break

if a == 0:
    print(0)
elif e !=-1:
    for i in range(e+1, N):
        if c[i][1] >= 2:
            b = c[i][0]
            break
    if b == 0:
        print(0)
    else:
        print(a*b)
else:
    print(a*b)
import sys

sys.setrecursionlimit(10**8)
h,w=map(int,input().split())
g=[list(input()) for _ in range(h)]
for x in range(h):
    for y in range(w):
        if g[y][x]=="#":
            k=0
            for i,j in [(1,0),(-1,0),(0,1),(0,-1)]:
                nx=x+i
                ny=y+j
                if nx<0 or nx>=h or ny<0 or ny>=w:
                   continue
                if g[ny][nx]==".":
                    k+=1
            if k==4:
                print("No")
                exit()
print("Yes")

### FIXED CODE ###

h,w=map(int,input().split())
g=[list(input()) for _ in range(h)]
for x in range(h):
    for y in range(w):
        if g[x][y]=="#":
            k=0
            for i,j in [(1,0),(-1,0),(0,1),(0,-1)]:
                nx=x+i
                ny=y+j
                if nx<0 or nx>=h or ny<0 or ny>=w:
                   continue
                if g[nx][ny]==".":
                    k+=1
            if k==4:
                print("No")
                exit()
print("Yes")
# 4 5 (4 cities and 5 steps)
# 3 2 4 1

# 1 => 3
# 2 => 2
# 3 => 4
# 4 => 1

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

paths = {}

for i in range(N):
    paths[i+1] = A_i[i]

# print('paths:', paths)

# 6 5 2 5 3 2

# 1 => 6 (1)
# 6 => 2 (2)
# 2 => 5 (3)
# 5 => 3 (4)
# 3 => 2 (5)

# loop_steps = 5 - 2 - 1 = 2
# 5 + 2 * m + r = 727202214173249351
# steps + loop_steps * m + r = K
# r = (K - steps) % loop_steps

state = 1
steps = 0
flag = False
known_states = {}

while steps < K:
    known_states[state] = steps # state => 2, steps => 2

    state = paths[state] # state => 5
    steps += 1 # steps => 3

    # print(f'steps: {steps}, state: {state}')

    if state in known_states and not flag: # state => 2 steps => 5
        loop_steps = steps - known_states[state] - 1
        steps = K - ((K - steps) % loop_steps)
        print('steps:', steps)
        flag = True
        # print('loop detected')


print(state)


### FIXED CODE ###

# 4 5 (4 cities and 5 steps)
# 3 2 4 1

# 1 => 3
# 2 => 2
# 3 => 4
# 4 => 1

# 1 (0)
# 1 => 3 (1)
# 3 => 4 (2)
# 4 => 1 (3)

# 2 を作る 5 と2 と 1 を使う
# 2  = (5 - 3) % 2 + 3 - 1

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

paths = {}

for i in range(N):
    paths[i+1] = A_i[i]

# print('paths:', paths)

# 6 5 2 5 3 2

# 1 => 6 (1)
# 6 => 2 (2)
# 2 => 5 (3)
# 5 => 3 (4)
# 3 => 2 (5)

# loop_steps = 5 - 2 - 1 = 2
# 5 + 2 * m + r = 727202214173249351
# steps + loop_steps * m + r = K
# r = (K - steps) % loop_steps

state = 1
steps = 0
flag = False
known_states = {}

while steps < K:
    known_states[state] = steps # state => 2, steps => 2

    state = paths[state] # state => 5
    steps += 1 # steps => 3

    # print(f'steps: {steps}, state: {state}')

    if state in known_states and not flag: # state => 2 steps => 5
        loop_steps = steps - known_states[state]
        K = (steps - loop_steps) + (K - (steps - loop_steps))  % loop_steps
        # print('loop_steps:', loop_steps)
        # print('steps - loop_steps:', steps - loop_steps)
        # print('K:', K)
        state = 1
        steps = 0
        # print('steps:', steps)
        flag = True
        # print('loop detected')



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

B = [0]*N

for k in range(K):

  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1

  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) = N:
    break

print(A)

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
 
 
for k in range(K):
  B = [0]*N
  for i in range(N): 
    start = max(0, i-A[i])
    end = min(N, i+A[i]+1)
    B[start] += 1
    if end <= N - 1:
      B[end] -= 1
 
  for i in range(1, N):
    B[i] = B[i-1] + B[i] 
  A = B
  if min(A) == N:
    break
 
print(*A)
n = int(input())
a = [int(input()) for _ in range(n)]
a1 = sorted(a)
if a1[n-1]==a1[n-2]:
  flag = True ## true = have repeat
  maxone = a1[n-1]
else:
  flag = False ## false = no repeat
  maxone = a1[n-1]
  maxtwo = a1[n-2]
for i in range(n):
  if a[i]==1max and flag==True: print(maxone)
  elif a[i]==1max and flag==False: print(maxtwo)
  elif a[i]!=1max: print(maxone)


### FIXED CODE ###

n = int(input())
num = []
maxnum = 0
count = 1
for i in range(n):
  a = int(input())
  if a>maxnum:
    maxnum = max(maxnum,a)
    count = 1
  elif a==maxnum:
    count += 1
  num.append(a)
  
for i in range(n):
  if count>1:
    print(maxnum)
  else:
    if num[i]!=maxnum:
      print(maxnum)
    else:
      subnum = num[0:i] + num[i+1:n]
      subnum = sorted(subnum)
      print(subnum[n-2])
X=int(input())
while True:
    for x in range(2,X):
        if X%x==0:
            break
    else:
        print(x)
        break
    X+=1

### FIXED CODE ###

X=int(input())
while True:
    for x in range(2,X):
        if X%x==0:
            break
    else:
        print(X)
        break
    X+=1
a,b = map(int() , input().split())
count=0
for i in range(1,a+1):
    for n in range(1b+1):
        if i==n:
            count+=1

### FIXED CODE ###

a,b=map(int,input().split())
if b>=a:
  print(a)
else:
  print(a-1)
N = int(input())
from bisect import bisect_left
from itertools import accumulate
a = map(int, input().split())
A = list(accumulate(a))
m = A[-1]//2
i = bisect_left(A, m)
ans1 = abs(A[-1] - A[i] - A[i])
ans2 = abs(A[-1] - A[i-1] - A[i-1]) if i >= 1 else ans1
print(min(ans1,ans2))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
a = sum(A) - A[0]
s = A[0]
ans = abs(s - a)
for i in range(1,N-1):
    a -= A[i]
    s += A[i]
    ans = min(ans, abs(s - a))
print(ans)
num = int(input())

print("{1}".format(num^3))


### FIXED CODE ###

num = int(input())

print("{0}".format(num**3))
# -*- coding: utf-8 -*-


if __name__ == '__main__':
    # スペース区切りの整数の入力
    b, c = map(int, input().split())
    # b, c = map(int, input().split())
    print(b * c / 2.0)


### FIXED CODE ###

# -*- coding: utf-8 -*-


if __name__ == '__main__':
    # スペース区切りの整数の入力
    b, c, d = map(int, input().split())
    # b, c = map(int, input().split())
    print(int(b * c / 2.0))
n,t = map(int,input().split())
s = []
dp = [[0]*(t) for _ in range(n+1)]
for _ in range(n):
    a,b = map(int,input().split())
    s.append([a,b])
s.sort()
ans = 0
#dp[i+1][j] .. i番目までのものから時間の総和がt以下となる時
for i in range(n):
    ans = max(ans,max(dp[:i][:])+reward) #それを最後に食した場合答えとなる
    time = s[i][0]
    reward = s[i][1]
    for j in range(t):
        if time > j:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-time])
print(ans)

### FIXED CODE ###

n, t = map(int, input().split())
 
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
 
a = []
b = []
for ai, bi in ab:
    a.append(ai)
    b.append(bi)
 
dp = [[0 for j in range(t+1)] for i in range(n+1)]
 
for i in range(n):
    for j in range(t):
        if j + a[i] <= t-1:
            if dp[i+1][j + a[i]] < dp[i][j] + b[i]:
                dp[i+1][j + a[i]] = dp[i][j] + b[i]
        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j]
 
ans = 0
 
for i in range(n):
    ans = max(ans, dp[i][t-1] + b[i])
 
print(ans)
N = int(input())
 
i=1
x = 0
 
while True:
    m = 10 ** i - 1
    if N <= m:
      x += (N - (10 ** (i-1) - 1))
      break
	x += m
    i += 1
print(x)

### FIXED CODE ###

N = int(input())
 
i=1
x = 0
 
while True:
  m = 10 ** i - 1
  if N <= m:
    x += max((N - (10 ** (i-1) - 1)), 0)
    break
  x += (m - (10 ** (i-1) - 1))
  i += 2
print(x)
# equeue

from collections import deque
import heapq


def main():
    N, K = map(int, input().split())
    V = list(map(int, input().split()))
    res = 0
    for pull in range(K+1):
        push = K - pull
        if push < 0:
            continue
        for left_push in range(push+1):
            tmp_que = deque(V)
            tmp_heap = []
            heapq.heapify(tmp_heap)
            right_push = push - left_push
            for _ in range(left_push):
                heapq.heappush(tmp_heap, tmp_que.popleft())
            for _ in range(right_push):
                heapq.heappush(tmp_heap, tmp_que.pop())

            tmp_res = sum(tmp_que)
            for i in range(min(push, pull)):
                x = heapq.heappop(tmp_heap)
                if x >= 0:
                    heapq.heappush(tmp_heap, x)
                    break

            res = max(res, sum(tmp_heap))
    print(res)
    return


if __name__ == "__main__":
    main()

### FIXED CODE ###

n,k=map(int,input().split())
lists=list(map(int,input().split()))
ans=0
nums=min(n,k)
for j in range(1,nums+1):
    #スライドするときの数 j=0,1,2,3,4......numsまでとることができる
    #n<kの時max n　かつかくjに対して取り除けるのはk-j回めまでである
    #n>=kの時max k かつ　かくｊに対して取り除けるのはk-j回までである
    for m in range(j+1):
        sublist=lists[:m]+lists[n+m-j:]
        sublist=sorted(sublist)
        sublist.append(0)
        del_some=0
        while del_some<k-j and min(sublist)<0:
            del sublist[0]
            del_some+=1
        p=sum(sublist)
        ans=max(ans,p)
print(ans)
x,n = map(int, input().split())

if n == 0:
    print(x)
    exit()

p = list(map(int,input().split()))

allList=[]

for i in range(1,101):
    allList.append(i)
    
diff = set(allList) ^ set(p)

diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
if x != 100:
    b = diff[ind+1]
else:
    print(a)
    exit()

ax = abs(a-x)
bx = abs(b-x)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
    else:
        print(b)

if ax > bx:
    print(b)
    exit()

### FIXED CODE ###

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

if n == 0:
    print(x)
    exit()

p = list(map(int,input().split()))

allList=[]

for i in range(-201,301):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
b = diff[ind+1]
# print(a,b)

ax = abs(x-a)
bx = abs(x-b)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
        exit()
    else:
        print(b)
        exit()

if ax > bx:
    print(b)
else:
    print(a)