#include <iostream>
#include <cstdio>
#include <map>
#include <list>
#include <set>
#include <queue>

using namespace std;

const int N=1000005;
typedef unsigned long long ulong;

struct comp
{
    const bool operator()(int a, int b) const
    {
        return a>b;
    }
};

int n, k, s, uradjeno;
int a[N];
set<int, comp> heights;
ulong res=0;


int main()
{
    freopen("zetoni.in", "r", stdin);
    freopen("zetoni.out", "w", stdout);
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        heights.insert(a[i]);
        s+=a[i];
    }
    uradjeno=0;
    while(!heights.empty())
    {
        /*
        for(int i=0; i<n; i++)
        {
            fprintf(stderr, "%d ", ((uradjeno+a[i])>k)?k:(uradjeno+a[i]));
        }
        fprintf(stderr, "\n");
        */
        int biggest=*heights.begin();
        //fprintf(stderr, "najvisa zgrada: %d\n", uradjeno+biggest);
        heights.erase(heights.begin());

        //gledam koliko ima delova izmedju visokih zgrada
        //ovo se MORA optimizovati!
        ulong n_parts=1;
        int i=0;
        while(i<n&&a[i]>biggest) i++;
        for(; i<n; i++)
        {
            if(a[i]>biggest)
            {
                while(i<n&&a[i]>biggest) i++;
                if(i<n) n_parts++;
            }

        }
        //fprintf(stderr, "%d delova\n", n_parts);

        res+=n_parts*(k-biggest-uradjeno);
        uradjeno=k-biggest;
    }

    cout<<res<<endl;

    return 0;
}
