import sys

sys.setrecursionlimit(100000000)



line = input().rstrip().split()

N, L = list(map(int, line))





def solve2(trr, hour=0):

    N = len(trr)

    if sum(trr) == 0:

        return hour

    elif N == 1:

        trr[0] += 1

    elif N == 2:

        if trr[0] > trr[1]:

            trr[0] += 1

        else:

            trr[1] += 1

    elif N > 2:

        if trr[0] > trr[1]:

            trr[0] += 1

        if trr[N-1] > trr[N-2]:

            trr[N-1] += 1

        for i in range(1, N-1):

            if N > 2 and trr[i-1] < trr[i] > trr[i+1]:

                trr[i] += 1

    return solve([0 if t == L else t for t in trr], hour+1)





def solve(trr, N):

#    print trr

    if N == 1:

        return L - trr[0]

    elif N == 2:

        return (L - trr[0]) + (L - trr[1])

    best_hour = -1

    peaks = []

    if trr[0] > trr[1]:

        peaks.append(0)

    if trr[N-1] > trr[N-2]:

        peaks.append(N-1)

    peaks += [i for i in range(1, N-1) if trr[i-1] < trr[i] > trr[i+1]]

#    print peaks

    for i, p in enumerate(peaks):

        hour1 = hour2 = L - trr[p]

        p_tm1 = p

        while p_tm1+1 < N and trr[p_tm1] > trr[p_tm1+1]:

            hour1 += L - trr[p_tm1+1]

            p_tm1 += 1

        p_tm2 = p

#        print '%d %d' % (p, trr[p_tm2-1])

        while p_tm2-1 > -1 and trr[p_tm2] > trr[p_tm2-1]:

            hour2 += L - trr[p_tm2-1]

#            print hour2

            p_tm2 -= 1

#            print hour2

        if best_hour < hour1:

            best_hour = hour1

        if best_hour < hour2:

            best_hour = hour2

    return best_hour



print(solve([int(input().rstrip()) for _ in range(N)], N))
import sys

sys.setrecursionlimit(100000000)



line = input().rstrip().split()

N, L = list(map(int, line))





def solve(trr, N):

    if N == 1:

        return L - trr[0]

    elif N == 2:

        return (L - trr[0]) + (L - trr[1])

    best_hour = -1

    peaks = []

    if trr[0] > trr[1]:

        peaks.append(0)

    if trr[N-1] > trr[N-2]:

        peaks.append(N-1)

    peaks += [i for i in range(1, N-1) if trr[i-1] < trr[i] > trr[i+1]]

    for i, p in enumerate(peaks):

        hour1 = hour2 = L - trr[p]

        p_tm1 = p

        while p_tm1+1 < N and trr[p_tm1] > trr[p_tm1+1]:

            hour1 += L - trr[p_tm1+1]

            p_tm1 += 1

        p_tm2 = p

        while p_tm2-1 > -1 and trr[p_tm2] > trr[p_tm2-1]:

            hour2 += L - trr[p_tm2-1]

            p_tm2 -= 1

        if best_hour < hour1:

            best_hour = hour1

        if best_hour < hour2:

            best_hour = hour2

    return best_hour



print(solve([int(input().rstrip()) for _ in range(N)], N))
import sys

sys.setrecursionlimit(100000000)
line = input().rstrip().split()
N, L = list(map(int, line))


def solve2(trr, hour=0):
    N = len(trr)
    if sum(trr) == 0:
        return hour
    elif N == 1:
        trr[0] += 1
    elif N == 2:
        if trr[0] > trr[1]:
            trr[0] += 1
        else:
            trr[1] += 1
    elif N > 2:
        if trr[0] > trr[1]:
            trr[0] += 1
        if trr[N - 1] > trr[N - 2]:
            trr[N - 1] += 1
        for i in range(1, N - 1):
            if N > 2 and trr[i - 1] < trr[i] > trr[i + 1]:
                trr[i] += 1
    return solve([0 if t == L else t for t in trr], hour + 1)


def solve(trr, N):
    #    print trr
    if N == 1:
        return L - trr[0]
    elif N == 2:
        return (L - trr[0]) + (L - trr[1])
    best_hour = -1
    peaks = []
    if trr[0] > trr[1]:
        peaks.append(0)
    if trr[N - 1] > trr[N - 2]:
        peaks.append(N - 1)
    peaks += [i for i in range(1, N - 1) if trr[i - 1] < trr[i] > trr[i + 1]]
    #    print peaks
    for i, p in enumerate(peaks):
        hour1 = hour2 = L - trr[p]
        p_tm1 = p
        while p_tm1 + 1 < N and trr[p_tm1] > trr[p_tm1 + 1]:
            hour1 += L - trr[p_tm1 + 1]
            p_tm1 += 1
        p_tm2 = p
        #        print '%d %d' % (p, trr[p_tm2-1])
        while p_tm2 - 1 > -1 and trr[p_tm2] > trr[p_tm2 - 1]:
            hour2 += L - trr[p_tm2 - 1]
            #            print hour2
            p_tm2 -= 1
        #            print hour2
        if best_hour < hour1:
            best_hour = hour1
        if best_hour < hour2:
            best_hour = hour2
    return best_hour


print(solve([int(input().rstrip()) for _ in range(N)], N))

import sys

sys.setrecursionlimit(100000000)
line = input().rstrip().split()
N, L = list(map(int, line))


def solve(trr, N):
    if N == 1:
        return L - trr[0]
    elif N == 2:
        return (L - trr[0]) + (L - trr[1])
    best_hour = -1
    peaks = []
    if trr[0] > trr[1]:
        peaks.append(0)
    if trr[N - 1] > trr[N - 2]:
        peaks.append(N - 1)
    peaks += [i for i in range(1, N - 1) if trr[i - 1] < trr[i] > trr[i + 1]]
    for i, p in enumerate(peaks):
        hour1 = hour2 = L - trr[p]
        p_tm1 = p
        while p_tm1 + 1 < N and trr[p_tm1] > trr[p_tm1 + 1]:
            hour1 += L - trr[p_tm1 + 1]
            p_tm1 += 1
        p_tm2 = p
        while p_tm2 - 1 > -1 and trr[p_tm2] > trr[p_tm2 - 1]:
            hour2 += L - trr[p_tm2 - 1]
            p_tm2 -= 1
        if best_hour < hour1:
            best_hour = hour1
        if best_hour < hour2:
            best_hour = hour2
    return best_hour


print(solve([int(input().rstrip()) for _ in range(N)], N))

-def solve2(trr, hour=0): -    N = len(trr) -    if sum(trr) == 0: -        return hour -    elif N == 1: -        trr[0] += 1 -    elif N == 2: -        if trr[0] > trr[1]: -            trr[0] += 1 -        else: -            trr[1] += 1 -    elif N > 2: -        if trr[0] > trr[1]: -            trr[0] += 1 -        if trr[N - 1] > trr[N - 2]: -            trr[N - 1] += 1 -        for i in range(1, N - 1): -            if N > 2 and trr[i - 1] < trr[i] > trr[i + 1]: -                trr[i] += 1 -    return solve([0 if t == L else t for t in trr], hour + 1) - - -    #    print trr -    #    print peaks -        #        print '%d %d' % (p, trr[p_tm2-1]) -            #            print hour2 -        #            print hour2