#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;

#define mygetchar getchar
void reader(int *x) {
	int k = mygetchar(); *x = k - '0';
	while (1) {
		k = mygetchar();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}

int N, L, a[100009], c[50009], d[100009], dp[100009]; vector<int> x[50009];
int main() {
	reader(&N); reader(&L);
	for (int i = 0; i < N; i++) reader(&a[i]), c[L - a[i]]++;
	for (int i = 1; i < L; i++) c[i] += c[i - 1];
	for (int i = 0; i < N; i++) d[c[L - a[i] - 1]++] = i;
	for (int i = 0; i < N; i++) dp[d[i] + 1] = max(dp[d[i]], dp[d[i] + 2]) + (L - a[d[i]]);
	printf("%d\n", *max_element(dp, dp + N + 1));
	return 0;
}