n,k=map(int,input().split())
p=list(map(int,input().split()))
if n<=3:
    print(sum(p))
else:
    minimum=p[1]
    maximum=p[2]
    if minimum>maximum:
        minimum=p[2]
        maximum=p[1]
    for i in p:
        if maximum+i<=minimum+maximum:
            maximum=i
    print(maximum+minimum+p[0])
