CodeEff/ECCO huggingface dataset:
# Original solution
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ans = 0
b = []
for k in range(n):
    if k == 0:
        b = a.copy()
    else:
        for i in range(n):
            b[i] = min(a[(i-k)%n],b[i])
    cost = k*x+sum(b)
    if k == 0:
        ans = cost
    else:
        ans = min(ans,cost)
        if ans != cost:
            break
    if ans < (k+1)*x:
        break
print(ans)

# Optimized solution

def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)
			if cost_min != cost_k:
				break
		if cost_min < (k+1) *x:
			break
 
	return cost_min
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print((solve(n,x,a)))
# Original solution
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(input())
def ii():
    return list(map(int,input().split(" ")))
def s():
    return input()
def ss():
    return input().split(" ")
def slist():
    return list(input())

###########

n,x=ii()
a=ii()
mi=[[0 for j in range(n)] for k in range(n)]
for s in range(n):
    mi[s][0]=a[s]
    for m in range(1,n):
        mi[s][m]=min(mi[s][m-1],a[(s-m)%n])
ans=INF
for m in range(n):
    cnt=x*m+sum([mi[s][m] for s in range(n)])
    ans=min(cnt,ans)

print(ans)


# Optimized solution
n,x=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
t=[i for i in a]
s=10**15
for m in range(n):
    t=[min(t[j],a[(j-m)%n]) for j in range(n)]
    s=min(x*m+sum(t),s)
print(s)
# Original solution
import sys
import heapq
from collections import defaultdict as dd
input = sys.stdin.readline
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = float("inf")

class prim:
  def __init__(self, n, e):
    self.e = e
    self.n = n
  def MSTcost(self):
    h = []
    visited = [0] * (self.n + 1)
    ks = list(self.e.keys())
    b = pow(10, 10)
    for edge in self.e[ks[0]]:
      heapq.heappush(h, edge[1] * b + edge[0])
    res = 0
    visited[ks[0]] = 1
    while len(h):
      p = heapq.heappop(h)
      p0 = p // b
      p1 = p % b
      if visited[p1]: continue
      visited[p1] = 1
      for q in self.e[p1]:
        if visited[q[0]]:
          continue
        heapq.heappush(h, q[1] * b + q[0])
      res += p0
    return res
e = dd(list)
for k in range(N + 1):
  for i in range(N):
    e[N].append(((i + k) % N, a[i]))
    e[(i + k) % N].append((N, a[i]))
  pri = prim(N, e)
  res = min(res, pri.MSTcost() + k * x)
print(res)

# Optimized solution
import sys
input = sys.stdin.readline
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
res = float("inf")

t = [float("inf")] * N
for k in range(N + 1):
  for i in range(N):
    t[(i + k) % N] = min(t[(i + k) % N], a[i])
  res = min(res, sum(t) + k * x)
print(res)
# Original solution
import sys

class segment_():
    def __init__(self, init_val, n, segfunc):
        self.ide_ele = 10**9+1
        # num: n以上の最小の2のべき乗
        self.num = 1 << (n - 1).bit_length()
        self.seg = [self.ide_ele]*2*self.num
        self.segfunc = segfunc
        # set_val
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]
        # built
        for i in range(self.num-2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[2*k+1], self.seg[2*k+2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res

def main():
    n, x = list(map(int,sys.stdin.readline().split()))
    A = list(map(int,sys.stdin.readline().split()))

    seg_ = segment_(A, n, lambda a, b: min(a, b))
    ans = 10**18
    for k in range(n):
        t = 0
        for i in range(n):
            if k <= i:
                t += seg_.query(i-k, i+1)
            else:
                t += min(seg_.query(0, i+1), seg_.query(n-(k-i), n))
        ans = min(t+k*x, ans)
    print(ans)

if __name__ == '__main__':
    main()


# Optimized solution
import sys

n, x = list(map(int,sys.stdin.readline().split()))
A = list(map(int,sys.stdin.readline().split()))

ans = 10**18
mins = [a for a in A]
for k in range(n):
    for i in range(n):
        if k <= i:
            mins[i] = min(A[i-k], mins[i])
        else:
            mins[i] = min(A[n-(k-i)], mins[i])
    ans = min(sum(mins)+k*x, ans)
print(ans)
# Original solution
import sys

n, x = list(map(int,sys.stdin.readline().split()))
A = list(map(int,sys.stdin.readline().split()))

ans = 10**18
mins = [a for a in A]
for k in range(n):
    for i in range(n):
        if k <= i:
            mins[i] = min(A[i-k], mins[i])
        else:
            mins[i] = min(A[n-(k-i)], mins[i])
    ans = min(sum(mins)+k*x, ans)
print(ans)


# Optimized solution
n, x = list(map(int,input().split()))
A = list(map(int,input().split()))

ans = 10**18
mins = [a for a in A]
for k in range(n):
    for i in range(n):
        if k <= i:
            mins[i] = min(A[i-k], mins[i])
        else:
            mins[i] = min(A[n-(k-i)], mins[i])
    ans = min(sum(mins)+k*x, ans)
print(ans)
# Original solution
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

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

print(ans)

# Optimized solution
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

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

print(ans)
# Original solution
n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
s=[[10**12]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if j==0:s[i][j]=a[i]
        else:s[i][j]=min(s[i][j-1],a[(i-j)%n])
ans=10**12
for j in range(n):
    tmp=x*j
    for i in range(n):
        tmp+=s[i][j]
    ans=min(ans,tmp)
print(ans)


# Optimized solution
n,x=list(map(int,input().split()))
a=list(map(int,input().split()))
s=[[10**12]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if j==0:s[i][j]=a[i]
        else:s[i][j]=min(s[i][j-1],a[(i-j)%n])
ans=float("inf")
for j in range(n):
    tmp=x*j
    for i in range(n):
        tmp+=s[i][j]
    ans=min(ans,tmp)
print(ans)
# Original solution
import copy
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
l = copy.deepcopy(a)
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)

# Optimized solution
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
l = [float("INF")]*n
ans = float("INF")
for i in range(n):
    count = x*i
    for j in range(n):
        l[j] = min(l[j],a[(j-i)%n])
        count += l[j]
    ans = min(ans,count)
print(ans)
# Original solution
from collections import deque

class SlideMin:
    """
    スライド最小値\n
    各区間[ai, ai+leng]の最小値を取得する：O(n)\n
    self.que = [(i1, v1), (i2, v2), ..., (ik, vk)]\n
    i1 < ... < ik and v1 < ... < vk
    """
    def __init__(self, leng):
        self.que = deque([])
        self.leng = leng

    def top(self):
        return self.que[0]

    def getQue(self):
        return self.que

    def update(self, index, value):
        while self.que:
            if self.que[-1][1] >= value:
                self.que.pop()
            else:
                break

        self.que.append((index, value))

        if self.que[0][0] == index - self.leng:
            self.que.popleft()

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

def sol(n):
    # n個前までの最小値
    B = A + A
    que = SlideMin(n + 1)
    ret = [10**18] * N
    for i, a in enumerate(B):
        que.update(i, a)
        ret[i % N] = min(ret[i % N], que.top()[1])
    return sum(ret) + n * X

ans = sum(A)
for i in range(N):
    ans = min(ans, sol(i))
print(ans)


# Optimized solution
N, X = list(map(int, input().split()))
A = list(map(int, input().split()))
B = A[:]

ans = sum(A)
for x in range(1, N + 1):
    for i in range(N)[::-1]:
        if B[i] > A[i - x]:
            B[i] = A[i - x]
    ans = min(ans, sum(B) + x * X)
print(ans)
# Original solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
B = a[:] # 魔法の回数がk以下のときのスライムjをてに入れる最小の時間（ただし、魔法を唱える時間は最後に
         # 加えるのでここでは除いている
ans = 10 ** 13
for i in range(N):
    for j in range(N):
        if B[j] > a[j - i]:
            B[j] = a[j - i]
    tmp = sum(B) + i * x
    if ans > tmp:
        ans = tmp

print(ans)


# Optimized solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
B = a[:] # 魔法の回数がk以下のときのスライムjをてに入れる最小の時間（ただし、魔法を唱える時間は最後に
         # 加えるのでここでは除いている
ans = 10 ** 13
for i in range(N):
    B = [a[j - i] if B[j] > a[j - i] else B[j] for j in range(N)]
    tmp = sum(B) + i * x
    if ans > tmp:
        ans = tmp

print(ans)
# Original solution
N, x = list(map(int, input().split()))
a_list = list(map(int, input().split()))
ex_list = a_list.copy()
ex_list.extend(a_list)

ans = float("inf")
for i in range(N):
    cost = 0
    for j in range(N):
        cost += min(ex_list[N-i+j:N+1+j])

    cost += x * i
    ans = min(ans, cost)
print(ans)


# Optimized solution
N, x = list(map(int, input().split()))
a_list = list(map(int, input().split()))
ex_list = a_list.copy()
ex_list.extend(a_list)

ans = float("inf")
cost_list = [float("inf") for _ in range(N)]
for i in range(N):
    cost = 0
    for j in range(N):
        if i == 0:
            cost += ex_list[N + j]
            cost_list[j] = ex_list[N + j]
        else:
            tmp = cost_list[j]
            if tmp > ex_list[N - i + j]:
                cost_list[j] = ex_list[N - i + j]
                cost += ex_list[N - i + j]
            else:
                cost += tmp

    cost += x * i
    ans = min(ans, cost)
print(ans)
# Original solution
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
for i in range(1, N):
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = x * i + sum(BC)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)


# Optimized solution
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
xt = 0
for i in range(1, N):
	xt += x
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = xt + sum(BC)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)
# Original solution
from itertools import accumulate
from functools import reduce
N,x,*A = list(map(int, open(0).read().split()))
dp = [0]*N
for i in range(N):
  dp[i] = list(accumulate((A[i-j] for j in range(N)),min))
ans = reduce(min, (i*x+sum(a) for i,a in enumerate(zip(*dp))))
print(ans)

# Optimized solution
from itertools import accumulate
from functools import reduce
N,x,*A = list(map(int, open(0).read().split()))
dp =[list(accumulate((A[i-j] for j in range(N)),min)) for i in range(N)]
ans = reduce(min, (i*x+sum(a) for i,a in enumerate(zip(*dp))))
print(ans)
# Original solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



from queue import deque
n,x = list(map(int, input().split()))
a = list(map(int, input().split()))

def sub(p):
    k = p
    res = []
    q = deque([])
    # q: i0<i1<,..., a_i0>a_i1>,...であるようなi0, i1,... のキュー
    for i,num in enumerate(a):
        while q and a[q[-1]]>num:
            q.pop()
        q.append(i)
        if q[0]<=i-k:
            q.popleft()
        if i>=k-1:
            m = a[q[0]] # i-k+1,...iの中の最小値
            res.append(m)
    for j,num in enumerate(a):
        if len(res)>=n:
            break
        while q and a[q[-1] if q[-1]<n else q[-1]-n]>num:
            q.pop()
        q.append(j+n)
        if q[0]<=j+n-k:
            q.popleft()
        m = a[q[0] if q[0]<n else q[0]-n] # i-k+1,...iの中の最小値
        res.append(m)
    return sum(res)


ans = 10**15
for p in range(n):
    ans = min(ans, sub(p+1) + x*p)
print(ans)

# Optimized solution
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



from queue import deque
n,x = list(map(int, input().split()))
A = list(map(int, input().split()))

def sub(p):
    k = p
    res = []
    q = deque([])
    a = A + A[:k-1]
    # q: i0<i1<,..., a_i0>a_i1>,...であるようなi0, i1,... のキュー
    for i,num in enumerate(a):
        while q and a[q[-1]]>num:
            q.pop()
        q.append(i)
        if q[0]<=i-k:
            q.popleft()
        if i>=k-1:
            m = a[q[0]] # i-k+1,...iの中の最小値
            res.append(m)
    return sum(res)


ans = 10**15
for p in range(n):
    ans = min(ans, sub(p+1) + x*p)
print(ans)
# Original solution
from functools import lru_cache

# 入力
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))

# a_i, a_{i + 1}, ..., a_j の最小値
@lru_cache(maxsize=None)
def f(i, j):
    return (
        a[i] if i == j else
        min(f(i, (j - 1) % N), a[j])
    )

# 変色回数を0からN-1まで決め打ちして解を求める
ans = min(
    sum(f(i, (i + k) % N) for i in range(N)) + k * x
    for k in range(N)
)

# 出力
print(ans)


# Optimized solution
# 入力
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))

dp = [[0 for _ in range(N)] for i in range(N)]
for i in range(N):
    dp[i][i] = a[i]
    for k in range(1, N):
        j = (i + k) % N
        dp[i][j] = min(dp[i][(j - 1) % N], a[j])

# 変色回数を0からN-1まで決め打ちして解を求める
ans = min(
    sum(dp[i][(i + k) % N] for i in range(N)) + k * x
    for k in range(N)
)

# 出力
print(ans)
# Original solution
N,X = list(map(int, input().split()))
A = list(map(int, input().split()))

ans = float("inf")
for loop in range(0, N+1):
  mxcnt = loop
  NC=A[:]
  for i in range(2*N+1):
    if i >=N: i%=N    
    pcnt=1
    pi=(i+1)%N
    v=A[i]
    while pcnt<=mxcnt:
      if v>=NC[pi]: break   
      NC[pi]=v
      pcnt+=1
      pi=(pi+1)%N
    tmp = (mxcnt)*X + sum(NC)
    ans = min(tmp, ans)
    # print("loop: ", loop, NC)
print(ans)
exit(0)


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

ans = float("inf")
bik = A[:]

get_idx_back = lambda idx,b: idx-b if idx>=b else idx+N-b

for loop in range(0, N+1):
  if loop == 0:
      bik = A[:]
  else: 
      for i in range(N):
          bik[i] = min(bik[i], A[ get_idx_back(i, loop) ])

  tmp = (loop)*X + sum(bik)

  ans = min(tmp, ans)
print(ans)
exit(0)
# Original solution
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)


# Optimized solution

def solve_():
    import itertools
    N, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    s_cost = a.copy()
    cost = sum(s_cost)

    for k, i in itertools.product(list(range(1, N)), list(range(N))):
        s_cost[i] = a[(i - k) % N] if s_cost[i] > a[(i - k) % N] else s_cost[i]
        if i == N - 1 and cost > k*x + sum(s_cost):
            cost = k*x + sum(s_cost)

    print(cost)

solve_()
# Original solution
N, x, *A = list(map(int, open(0).read().split()))

ans = float("inf")
for i in range(N):
    ans = min(ans, sum(A) + x * i)
    A = [min(a, b) for a, b in zip(A, [A[-1]] + A[:-1])]

print(ans)

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

ans = float("inf")
for k in range(N):
    ans = min(ans, sum(A) + x * k)
    A = [min(a, b) for a, b in zip(A, A[-1:] + A[:-1])]

print(ans)
# Original solution
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a += a
ans = float("inf")
for i in range(1, n+1):
    t = 0
    for j in range(n):
        t += min(a[j:j + i])
    ans = min(ans, t+10*(i-1))
print(ans)

# Optimized solution
n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a += a
mah = [10000000000]*n
ans = float("inf")
for i in range(1, n+1):
    t = 0
    for j in range(n):
        if mah[j] > a[j + i]:
            mah[j] = a[j+i]
        t += mah[j]
    ans = min(ans, t+x*(i-1))
print(ans)
# Original solution
N, x = list(map(int,input().split()))
A = list(map(int,input().split()))

ans = sum(A)
A = A+A

for k in range(1,N):
    L = [0]*N
    for l in range(N):
        T = A[N+l-k:N+l+1]
        L[l] = min(T)
    ans = min(ans,sum(L)+k*x)

print(ans)


# Optimized solution
N, x = list(map(int,input().split()))
A = list(map(int,input().split()))
T = [A[k] for k in range(N)]

ans = sum(A)
A = A+A

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

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

B = A[:]
ans = sum(A)

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

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

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(B[i], A[i - k]) for i in range(N)]
    ans = min(ans, sum(B) + k * x)
print(ans)
# Original solution
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

a = a+a

INF = float("inf")

# 区間内最小を探す
itv_min = [[INF for _ in range(2*n)] for _ in range(n)]
for st in range(n):
    mn = a[st]
    itv_min[st][st] = mn
    for ed in range(st+1,st+n):
        mn = min(mn, a[ed])
        itv_min[st][ed] = mn

# 魔法を唱える回数を固定
ans = INF
for k in range(n):
    temp = 0
    for st in range(n):
        temp += itv_min[st][st+k]
        
    ans = min(ans, temp+k*x)

print(ans)

# Optimized solution
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

mins = [ai for ai in a]
a2 = a+a

ans = sum(mins)
for k in range(n):
    for i in range(n):
        mins[i] = min(mins[i],a2[i+k])
    
    temp = sum(mins)    
    ans = min(ans, temp + k*x)
    
print(ans)
# Original solution
def main():
    N, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    ans = float("INF")
    b = [float("INF")]*N
    for k in range(N):
        temp_ans = k*x
        for i in range(N):
            b[i] = min(b[i],a[i-k])
            temp_ans += b[i]
        ans = min(ans,temp_ans)
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    N, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    ans = float("INF")
    b = [float("INF")]*N
    for k in range(N):
        temp_ans = k*x
        for i in range(N):
            t = a[i-k]
            if t < b[i]:
                b[i] = t
            temp_ans += b[i]
        ans = min(ans,temp_ans)
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
import sys
input = sys.stdin.buffer.readline

def main():
    N,x = list(map(int,input().split()))
    count = N
    N *= 2
    a = list(map(int,input().split()))
    ans = sum(a)
    a += a
    
    def segfunc(x,y):
        return min(x,y)
        
    def init(init_val):
        for i in range(N):
            seg[i+num-1] = init_val[i]
        for i in range(num-2,-1,-1):
            seg[i] = segfunc(seg[2*i+1],seg[2*i+2])
                
    def update(k,x):
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[2*k+1],seg[2*k+2])
            
    def query(p,q):
        if q <= p:
            return ide_ele
        p += num-1
        q += num-2
        ret = ide_ele
        while q-p > 1:
            if p&1 == 0:
                ret = segfunc(ret,seg[p])
            if q&1 == 1:
                ret = segfunc(ret,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        ret = segfunc(segfunc(ret,seg[p]),seg[q])
        return ret
        
    ide_ele = 10**15
    num = 2**(N-1).bit_length()
    seg = [ide_ele]*2*num
    init(a)
    
    for i in range(count-1):
        i += 1
        time = i*x
        for now in range(count):
            ret = query(now+count-i,now+count+1)
            time += ret
        ans = min(ans,time)
        
    print(ans)

if __name__ == "__main__":
    main()
    


# Optimized solution
import sys
input = sys.stdin.buffer.readline

def main():
    N,x = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = a.copy()
    
    ans = 10**15
    for i in range(N):
        time = i*x+sum(b)
        ans = min(ans,time)
        for now in range(N):
            b[now] = min(b[now],a[(now-i-1+N)%N])

    print(ans)

if __name__ == "__main__":
    main()
# Original solution
#b faster
#m_i(k) = min(m_i(k-1), a_(i-k))
n,x =  [int(i) for i in input().split()]
a   =  [int(i) for i in input().split()]
m   =  a[::]
a.extend(a)

min_cost = 10**10

for k in range(n):
    cost = x * k
    for i in range(n,2*n):
        mini = min(m[i-n], a[i-k])
        m[i-n] = mini
        cost += mini
    min_cost = min(min_cost, cost)
print(min_cost)

# Optimized solution
#b faster
#m_i(k) = min(m_i(k-1), a_(i-k))
# http://agc004.contest.atcoder.jp/data/agc/004/editorial.pdf
n,x =  [int(i) for i in input().split()]
a   =  [int(i) for i in input().split()]
m   =  a[::]
a.extend(a)

min_cost = sum(a)

for k in range(n):
    #cost = x * k
    for i in range(n,2*n):
        m[i-n] = min(m[i-n], a[i-k])
        #cost += mini
    min_cost = min(min_cost, x*k + sum(m))
print(min_cost)
# Original solution
n,x,*a=list(map(int,open(0).read().split()));i,m=0,1e18;exec('m=min(m,sum(a)+x*i);i+=1;a=[min(t)for t in zip(a,a[-1:]+a)];'*n);print(m)

# Optimized solution
n,x,*a=list(map(int,open(0).read().split()))
m=1e18
for i in range(n):m=min(m,sum(a)+x*i);a=[min(t)for t in zip(a,a[-1:]+a)]
print(m)
# Original solution
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()

min_index = A.index(min(A))
B = A[min_index:] + A[:min_index]

cost = [[INF] * N for i in range(N)]
for i in range(N):
    cost[i][0] = B[i]

for i in range(N):
    for magic in range(1, N):
        cost[i][magic] = min(cost[i][magic], min(B[max(0, i - magic)], cost[i][magic - 1]))

ans = INF
for magic in range(N):
    tmp = 0
    for i in range(N):
        tmp += cost[i][magic]
    ans = min(ans, tmp + magic * x)

print(ans)

# Optimized solution
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()

min_index = A.index(min(A))
B = A[min_index:] + A[:min_index]

cost = [B[i] for i in range(N)]

ans = INF
for magic in range(N):
    for i in range(N):
        if i - magic >= 0:
            cost[i] = min(cost[i], B[i - magic])

    ans = min(ans, sum(cost) + x * magic)

print(ans)