CodeEff/ECCO huggingface dataset:
# Original solution
X, N = list(map(int, input().split(' ')))
if N == 0:
    print(X)
else:
    ls = list(map(int, input().split(' ')))
    diff = -1
    for i in range(101, -1, -1):
        if i not in ls:
            if diff == -1:
                diff = abs(i - X)
                result = i
            else:
                diff = min(diff, abs(i - X))
                if diff == abs(i - X):
                    result = i
    print(result)

# Optimized solution
X, N = list(map(int, input().split(' ')))
if N == 0:
    print(X)
else:
    ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)
# Original solution
import queue

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

if N!=0:
    p = list(map(int,input().split()))
else:
    p=[]

q = queue.Queue()

q.put(X)

while True:
    t = q.get()
    if t in p:
        q.put(t-1)
        q.put(t+1)
    else:
        print(t)
        break


# Optimized solution
X,N = list(map(int,input().split()))

if N!=0:
    p = list(map(int,input().split()))
else:
    p=[]

d = {n: 1 for n in p}

a = X
b = X
while True:
    if d.get(a) != 1:
        print(a)
        break
    elif d.get(b) != 1:
        print(b)
        break
    else:
        a -= 1
        b += 1
# Original solution
import sys
x,n=list(map(int,input().split()))
ans=10000
ansaa=10000
ans1=[]
ans2=[]
ans3=[]
if n>0:
    l=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
for i in range(len(l)):
    if abs(ans-l[i])<ans:
        ans1.append(l[i])
        ans1.append(l[i]-1)
        ans1.append(l[i]+1)
ans1=sorted(ans1)
for j in range(len(ans1)):
    if abs(x-ans1[j])<ans and ans1[j] not in l:
        ans2.append(ans1[j])
        ans=min(ans,x-ans1[j])
print((max(ans2)))

# Optimized solution
import sys
x,n=list(map(int,input().split()))
ans=10000
ans1=[]
ans2=[]
if n>0:
    l=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
for i in range(len(l)):
    if abs(ans-l[i])<ans:
        ans1.append(l[i])
        ans1.append(l[i]-1)
        ans1.append(l[i]+1)
ans1=sorted(ans1)
for j in range(len(ans1)):
    if abs(x-ans1[j])<ans and ans1[j] not in l:
        ans2.append(ans1[j])
        ans=min(ans,x-ans1[j])
print((max(ans2)))
# Original solution
x,n = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
P = [*list(map(int,input().split()))]

ans = 100000000 # inf
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = x-d
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = x+d
print(ans)


# Optimized solution
x,n = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
P = [*list(map(int,input().split()))]
ans = 100+100 # inf = x + d + 1
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = x-d
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = x+d
print(ans)
# Original solution
x, n = list(map(int, input().split()))
if n == 0: print(x); exit()
P = [*list(map(int, input().split()))]
for d in range(100): # [0,100)
    a = x - d
    if a not in P: print(a); exit()
    a = x + d
    if a not in P: print(a); exit()


# Optimized solution
x, n = list(map(int, input().split()))
if n == 0: print(x); exit()
C = [0]*(101+1) # candidate:[0,101]
for p in map(int, input().split()):
    C[p] = 1
ans = x
d = 1000000000
for c in range(101+1):
    if not C[c] and d > abs(x - c):
        d = abs(x - c)
        ans = c
print(ans)
# Original solution
x, n = list(map(int, input(). split()))
p = list()
if n > 0:
  p = list(map(int, input(). split()))
if x not in p:
  print(x)
else:
  d = 1
  while True:
    if x-d not in p:
      print((x-d))
      break
    if x+d not in p:
      print((x+d))
      break
    d += 1

# Optimized solution
import sys
x, n = list(map(int, input(). split()))
l = [0]*n
m = [0]*200
ans = 0
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
else:
  for j in range(1, 200):
    if m[j] != 2:
      a = x-j
      A = x+j
      b = p.count(a)
      B = p.count(b)
      if b == 0:
        ans = a
      else:
        ans = A
      break
  print(ans)
# Original solution
import bisect
X, N=list(map(int, input().split()))
if N==0:print(X);exit()
p=sorted(list(map(int, input().split())))
#print(p)
m=min(p)-1
M=max(p)+1
#for i in range(m,M+1):
#  p.append(i)
#p=sorted(p)
m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print((min(i,j)))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)

# Optimized solution
X, N=list(map(int, input().split()))
if N==0:print(X);exit()
p=sorted(list(map(int, input().split())))

m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print((min(i,j)))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)
# Original solution
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x,n = LI()
    p = LI()
    f = [1]*(200)
    for i in p:
        f[i] = 0
    ans = x
    m = 0
    for i in range(200):
        if f[i]:
            d = abs(i-x)
            if d < ans:
                ans = d
                m = i
    print(m)
    return

#Solve
if __name__ == "__main__":
    solve()


# Optimized solution
x, n = list(map(int, input(). split()))
m = [0]*200
ans = 0
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  quit()
for i in range(n):
  l = abs(x-p[i])
  m[l] += 1
if m[0] == 0:
  print(x)
else:
  for j in range(1, 200):
    if m[j] < 2:
      a = x-j
      A = x+j
      if a not in p:
        ans = a
      else:
        ans = A
      break
  print(ans)
# Original solution
import sys
input=sys.stdin.readline

x,n=list(map(int,input().split()))
if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    a=0
    d=0
    while a==0:
        if x-d in p:
            if x+d in p:
                d+=1
            else:
                a=x+d
        else:
            a=x-d
    print(a)

# Optimized solution
import sys
input=sys.stdin.readline
x,n=list(map(int,input().split()))
if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    d=0
    while True:
        if x-d in p:
            if x+d in p:
                d+=1
            else:
                a=x+d
                break
        else:
            a=x-d
            break
    print(a)
# Original solution
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    p.sort()
    y = 0

    for i in range(n):
        if p[i] <= x:
            y = i
            if i != n-1 and x < p[i+1]:
                break 

    i = 0
    while 1 == 1:
        if 0 <= y - i and x - i != p[y - i]:
            print((x - i))
            break
        if y + i < n and x + i != p[y + i]:
            print((x + i))
            break
        i = i + 1

# Optimized solution
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))

    p.sort()
    y = 0

    for i in range(n):
        if p[i] <= x:
            y = i
            if i != n-1 and x < p[i+1]:
                break 

    i = 0
    while 1 == 1:
        if y - i < 0:
            print((p[0] - 1))
            break
        elif x - i != p[y - i]:
            print((x - i))
            break
        if n <= y + i:
            print((p[n - 1] + 1))
            break
        elif x + i != p[y + i]:
            print((x + i))
            break
        i = i + 1
# Original solution
X, N = list(map(int, input().split()))
if N > 0:
    P = list(map(int, input().split()))
    res = float('Inf')
    A = [0]*101
    for n in range(N):
        A[P[n]-1] += 1
    cnt = 1
    man = float('Inf')
    for a in A:
        if a == 0:
            total = abs(X - cnt)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    if abs(X - 0) <= res:
        man = 0
    print(man)
else:
    print(X)

# Optimized solution
X, N = list(map(int, input().split()))
if N > 0:
    P = list(map(int, input().split()))
    A = [0]*102
    cnt = 0
    res = float('Inf')
    for n in range(N):
        A[P[n]] += 1
    for a in A:
        if a == 0:
            total = abs(X - cnt)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    print(man)
else:
    print(X)
# Original solution
x,n,*p=list(map(int,open(0).read().split()))
print((min({*list(range(999))}-{*p},key=lambda y:abs(y-x))))

# Optimized solution
x,n,*p=list(map(int,open(i:=0).read().split()))
while x in p:x+=(-1)**i*i;i+=1
print(x)
# Original solution
from bisect import bisect_left,bisect

x,N,*p = list(map(int,open(0).read().split()))
dif = 300
near = 300
all_ = set(range(0,102))

for i in p:
    d = abs(i - x)
    if dif > d:
        dif = d
        near = i
left = list(all_ - set(p))        

dif2 = 300
near = 300
for i in left:
    d = abs(x-i)
    if d < near:
        near = d
        dif2 = i
print(dif2)        
    

# Optimized solution
X,N,*p = list(map(int,open(0).read().split()))
dif = 100
ans = -1
for i in range(102):
    a = abs(X-i)
    if i in p:
        continue
    if  a < dif:
        dif = a
        ans = i
print(ans)
# Original solution
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()

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

for d in range(x + 2):
	for s in [-1, 1]:
		a = x + s * d
		if a not in p:
			print(a)
			exit()

# Optimized solution
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))

for d in range(x + 2):
	if x - d not in p:
		print((x-d))
		exit()
	if x + d not in p:
		print((x+d))
		exit()
# Original solution

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = [int(i) for i in input().split(" ")]
    else:
        P = []

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()


# Optimized solution

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = set([int(i) for i in input().split(" ")])
    else:
        P = set()

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()
# Original solution
x, n = list(map(int, input().split()))
if n==0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    while i < n and p[i] < x:
        i += 1

    if p[i] != x:
        print(x)
    else:
        j = 1
        up = x+j
        down = x-j
        while True:
            if i-j>=0 and p[i-j] != x-j:
                print((x-j))
                break
            if i+j<n and p[i+j] != x+j:
                print((x+j))
                break
            j += 1


# Optimized solution
x, n = list(map(int, input().split()))
if n==0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    while i < n and p[i] < x:
        i += 1

    if p[i] != x:
        print(x)
    else:
        j = 1
        up = x+j
        down = x-j
        while True:
            if i-j>=0 and p[i-j] != x-j:
                print((x-j))
                break
            elif i-j < 0:
                print((x-j))
                break
            if i+j<n and p[i+j] != x+j:
                print((x+j))
                break
            elif i+j >= n:
                print((x+j))
                break
            j += 1
# Original solution
n,m=list(map(int,input().split()))
N=3*n
d=[[0]*(N+1) for i in range(N+5)]
d[0][0]=1
for i in range(N):
  a,b,c,e,*_=d[i:]
  for j in range(N):
    J=j+1
    b[j]=(b[j]+a[j])%m
    c[J]=(c[J]+a[j]*(i+1))%m
    e[J]=(e[J]+a[j]*(i+1)*(i+2))%m
print((sum(d[N][:n+1])%m))


# Optimized solution
n,m=list(map(int,input().split()))
N=3*n
d=[[0]*(N+1) for i in range(N+4)]
d[0][0]=1
for i in range(N):
  a,b,c,e=d[i:i+4]
  for j in range(N):J=j+1;b[j]=(b[j]+a[j])%m;c[J]=(c[J]+a[j]*(i+1))%m;e[J]=(e[J]+a[j]*(i+1)*(i+2))%m
print((sum(d[N][:n+1])%m))
# Original solution
N,mod=list(map(int,input().split()))

DP=[[0]*(N+5) for i in range(3*N+5)]
DP[0][0]=1

for i in range(3*N):
    for j in range(N+1):
        DP[i+1][j]+=DP[i][j]
        DP[i+2][j+1]+=((3*N-i)-1)*DP[i][j]
        DP[i+3][j+1]+=((3*N-i)-1)*((3*N-i)-2)*DP[i][j]

ANS=0
for i in range(N+1):
    ANS+=DP[3*N][i]
print((ANS%mod))

# Optimized solution
N,mod=list(map(int,input().split()))

DP=[[0]*(N+5) for i in range(3*N+5)]
DP[0][0]=1

for i in range(3*N):
    for j in range(N+1):
        DP[i][j]%=mod
        DP[i+1][j]+=DP[i][j]
        DP[i+2][j+1]+=((3*N-i)-1)*DP[i][j]
        DP[i+3][j+1]+=((3*N-i)-1)*((3*N-i)-2)*DP[i][j]

ANS=0
for i in range(N+1):
    ANS+=DP[3*N][i]
print((ANS%mod))
# Original solution
N,mod=list(map(int,input().split()))

DP=[[0]*(N+5) for i in range(3*N+5)]
DP[0][0]=1

for i in range(3*N):
    for j in range(N+1):
        DP[i][j]%=mod
        DP[i+1][j]+=DP[i][j]
        DP[i+2][j+1]+=((3*N-i)-1)*DP[i][j]
        DP[i+3][j+1]+=((3*N-i)-1)*((3*N-i)-2)*DP[i][j]

ANS=0
for i in range(N+1):
    ANS+=DP[3*N][i]
print((ANS%mod))

# Optimized solution
N,m=list(map(int,input().split()))
M=3*N
DP=[[0]*(N+5) for i in range(M+5)]
DP[0][0]=1
for i in range(1,M+1):
    for j in range(N+1):
        DP[i][j]=(DP[i-1][j]+(M-i+1)*DP[i-2][j-1]+(M-i+1)*(M-i+2)*DP[i-3][j-1])%m
print((sum(DP[3*N][:N+1])%m))
# Original solution
from functools import lru_cache, reduce
from itertools import accumulate

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

@lru_cache(maxsize=None)
def mod_inv(x):
  x1, y1, z1 = 1, 0, x
  x2, y2, z2 = 0, 1, M
  while z1 != 1:
    d, m = divmod(z2, z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1%M

def gen_Y(i, A):
  yield A
  # sC2/1, (s-2)C2/2, (s-4)C2/3  ...
  s = 3*(N-i)
  r = s*(s-1)>>1
  d_r = (s<<1)-3
  for j in range(1, N-i+1):
    yield r * mod_inv(j)
    r -= d_r
    d_r -= 4

def gen_X():
  # sC3*2/1, (s-3)C3*2/2, (s-6)C3*2/3  ...
  yield 1
  a = N
  b = 3*N - 1
  for i in range(1, N+1):
    yield a * b * (b-1) * mod_inv(i)
    a -= 1
    b -= 3

def mul_mod(x, y):
  return x * y % M

def acc_mod(it):
  return accumulate(it, mul_mod)

ans = sum(sum(acc_mod(gen_Y(i, A))) for i, A in enumerate(acc_mod(gen_X())))%M

print(ans)

# Optimized solution
from functools import lru_cache

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

@lru_cache(maxsize=None)
def mod_inv(x):
  x1, y1, z1 = 1, 0, x
  x2, y2, z2 = 0, 1, M
  while z1 != 1:
    d, m = divmod(z2, z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1%M

def gen_Y(i):
  # sC2/1, (s-2)C2/2, (s-4)C2/3  ...
  s = 3*(N-i)
  r = s*(s-1)>>1
  d_r = (s<<1)-3
  for j in range(1, N-i+1):
    yield r * mod_inv(j)
    r -= d_r
    d_r -= 4

def gen_X():
  # sC3*2/1, (s-3)C3*2/2, (s-6)C3*2/3  ...
  a = N
  b = 3*N - 1
  for i in range(1, N+1):
    yield a * b * (b-1) * mod_inv(i)
    a -= 1
    b -= 3

def acc_mulmod(it, init=1):
  x = init
  yield x
  for y in it:
    x = x*y % M
    yield x

ans = sum(sum(acc_mulmod(gen_Y(i), A)) for i, A in enumerate(acc_mulmod(gen_X())))%M

print(ans)
# Original solution
import sys
sys.setrecursionlimit(1000000)

n = int(eval(input()))
alst = list(map(int, input().split()))
edges = [[] for _ in range(n)]
rev_edges = [[] for _ in range(n)]
for i in range(n):
  edges[i].append((i + alst[i]) % n)
  rev_edges[(i + alst[i]) % n].append(i)

def dfs(x, ret, edges, visited):
  visited[x] = True
  for e in edges[x]:
    if not visited[e]:
      dfs(e, ret, edges, visited)
  ret.append(x)

def dfs_rev(x, cycles, rev_edges, visited):
  visited[x] = True
  flag = False
  for e in rev_edges[x]:
    if not visited[e]:
      cycles.add(e)
      dfs_rev(e, cycles, rev_edges, visited)
      flag = True
    elif x == e:
      flag = True
  if flag:
    cycles.add(x)

order = []
visited = [False] * n
for i in range(n):
  if not visited[i]:
    dfs(i, order, edges, visited)
order.reverse()

visited = [False] * n
cycles = set()
for i in order:
  if not visited[i]:
    dfs_rev(i, cycles, rev_edges, visited)
print((len(cycles)))


# Optimized solution
import sys
sys.setrecursionlimit(1000000)

def dfs(x, order, edges, visited):
  visited[x] = True
  for e in edges[x]:
    if not visited[e]:
      dfs(e, order, edges, visited)
  order.append(x)

def dfs_rev(x, rev_edges, visited):
  visited[x] = True
  ret = 0
  for e in rev_edges[x]:
    if not visited[e]:
      ret += 1
      ret += dfs_rev(e, rev_edges, visited)
  return ret


n = int(eval(input()))
alst = list(map(int, input().split()))
edges = [[] for _ in range(n)]
rev_edges = [[] for _ in range(n)]
for i in range(n):
  edges[i].append((i + alst[i]) % n)
  rev_edges[(i + alst[i]) % n].append(i)

order = []
visited = [False] * n
for i in range(n):
  if not visited[i]:
    dfs(i, order, edges, visited)
order.reverse()

visited = [False] * n
cycles = 0
for i in order:
  if not visited[i]:
    a = dfs_rev(i, rev_edges, visited)
    if a > 0 or i in rev_edges[i]:
      a += 1
    cycles += a
print(cycles)
# Original solution
def mygets():
    return list(map(int, input().strip().split(' ')))

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)

def f(k, u):
    j = k - 1
    if j < 0:
        j = n - 1
    w = b1[j]
    if u < w:
        return u
    return w

for i in range(1, n):
    b2 = [f(k, u) for k, u in enumerate(a)]
    ans = min(ans, sum(b2) + i * x)
    b1 = b2

print(ans)

# Optimized solution
def mygets():
    return [int(v) for v in input().strip().split(' ')]

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)

for i in range(1, n):
    b2 = [u if u < b1[k - 1] else b1[k - 1] for k, u in enumerate(a)]
    ans = min(ans, sum(b2) + i * x)
    b1 = b2

print(ans)
# Original solution
N, X, *A = list(map(int, open(0).read().split()))


class SegmentTree:
    inf = 2 ** 31 - 1
    
    def __init__(self, n):
        """0-indexed."""
        x = 1
        while x < n:
            x *= 2

        self.n = x
        self.dat = [self.inf] * (2 * x - 1)
        
    def update(self, k, v):
        """Update dat[k] to v."""
        k += self.n - 1
        self.dat[k] = v
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
            
    def query(self, a, b, k=0, l=0, r=0):
        """Returns min in [a, b)."""
        if l >= r:
            r = self.n
            
        if b <= l or r <= a:
            return self.inf
        
        if a <= l and r <= b:
            return self.dat[k]
        
        vl = self.query(a, b, k * 2 + 1, l, (l + r) // 2)
        vr = self.query(a, b, k * 2 + 2, (l + r) // 2, r)
        return min(vl, vr)


st = SegmentTree(N)
for i, v in enumerate(A):
    st.update(i, v)

ans = 10 ** 10
for k in range(N):
    b = [0] * N
    for i in range(N):
        if i - k < 0:
            b[i] = min(st.query(0, i + 1), st.query(N - (k - i), N))
        else:
            b[i] = st.query(i - k, i + 1)
    ans = min(ans, k * X + sum(b))
print(ans)


# Optimized solution
N, X, *A = list(map(int, open(0).read().split()))

ans = sum(A)
b = A[:]
for k in range(1, N):
    for i in range(N):
        b[i] = min(b[i], A[i - k])
    ans = min(ans, k * X + sum(b))
print(ans)
# Original solution
N, x = list(map(int, input().split()))
A = list(map(int, input().split())) * 2
A = A[::-1]

effective_costs = [float('inf')] * N
ans = float('inf')

# 魔法を使う回数
for k in range(N):
    cost = 0
    for i in range(N):
        effective_costs[i] = min(effective_costs[i], A[i+k])
        cost += effective_costs[i]
    ans = min(ans, cost + k * x)

print(ans)


# Optimized solution
N, x = list(map(int, input().split()))
A = list(map(int, input().split())) * 2
A = A[::-1]

effective_costs = [float('inf')] * N
ans = float('inf')

# 魔法を使う回数
for k in range(N):
    effective_costs = [min(effective_costs[i], A[i+k]) for i in range(N)]
    ans = min(ans, sum(effective_costs) + k * x)

print(ans)
# Original solution
import sys
from copy import deepcopy
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
        ans = min(ans,sum(B)+k*x)

print(ans)


# Optimized solution
import sys
from copy import deepcopy
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
    ans = min(ans,sum(B)+k*x)

print(ans)
# Original solution
import sys
from copy import deepcopy
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
    ans = min(ans,sum(B)+k*x)

print(ans)


# Optimized solution
import sys
from copy import deepcopy
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,x = MI()
A = LI()
B = deepcopy(A)
A += A

ans = sum(B)
for k in range(1,N+1):  # 魔法を k 回唱える
    for i in range(N):
        B[i] = min(B[i],A[N+i-k])
    ans = min(ans,sum(B)+k*x)

print(ans)