#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int n;
    int m;
    cin >> n >> m;
    int nGranice[n];
    bool zid[n][m];
    for (int i = 0; i < n; ++i)
    {
        cin >> nGranice[i];
    }

    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
        {
            if (m - nGranice[i] > nGranice[i])
            {
                for (int k = 0; k < m; ++k)
                {
                    if (k > nGranice[i] - 1)
                    {
                        zid[i][k] = true;
                    }
                    else
                    {
                        zid[i][k] = false;
                    }
                }
            }
            else
            {
                for (int k = 0; k < m; ++k)
                {
                    if (k < nGranice[i])
                    {
                        zid[i][k] = true;
                    }
                    else
                    {
                        zid[i][k] = false;
                    }
                }
            }
        }
        else
        {
            bool zid_copy1[n][m];
            bool zid_copy2[n][m];

            for (int a = 0; a < n; ++a)
            {
                for (int b = 0; b < m; ++b)
                {
                    zid_copy1[a][b] = zid[a][b];
                    zid_copy2[a][b] = zid[a][b];
                }
            }

            for (int k = 0; k < m; ++k)
            {
                if (k < nGranice[i])
                {
                    zid_copy1[i][k] = true;
                }
                else
                {
                    zid_copy1[i][k] = false;
                }
            }

            for (int k = 0; k < m; ++k)
            {
                if (k > nGranice[i] - 1)
                {
                    zid_copy2[i][k] = true;
                }
                else
                {
                    zid_copy2[i][k] = false;
                }
            }

            int resultFirst = 0;
            int resultSecond = 0;

            for (int a = 0; a < m; ++a)
            {
                int obojeni = 0;
                int neobojeni = 0;
                for (int b = 0; b <= i; ++b)
                {
                    if (zid_copy1[b][a] == true)
                    {
                        ++obojeni;
                    }
                    else
                    {
                        ++neobojeni;
                    }
                }

                resultFirst += obojeni * neobojeni;

            }

            for (int a = 0; a < m; ++a)
            {
                int obojeni = 0;
                int neobojeni = 0;
                for (int b = 0; b <= i; ++b)
                {
                    if (zid_copy2[b][a] == true)
                    {
                        ++obojeni;
                    }
                    else
                    {
                        ++neobojeni;
                    }
                }

                resultSecond += obojeni * neobojeni;

            }

            if (resultFirst <= resultSecond)
            {
                for (int k = 0; k < m; ++k)
                {
                    if (k < nGranice[i])
                    {
                        zid[i][k] = true;
                    }
                    else
                    {
                        zid[i][k] = false;
                    }
                }
            }
            else
            {
                for (int k = 0; k < m; ++k)
                {
                    if (k > nGranice[i] - 1)
                    {
                        zid[i][k] = true;
                    }
                    else
                    {
                        zid[i][k] = false;
                    }
                }
            }


        }

    }

    int konacanRezultat = 0;

    for (int j = 0; j < m; ++j)
    {
        int obojeni = 0;
        int neobojeni = 0;
        for (int i = 0; i < n; ++i)
        {
            if (zid[i][j] == true)
            {
                ++obojeni;
            }
            else
            {
                ++neobojeni;
            }
        }
        konacanRezultat += obojeni * neobojeni;
    }

    cout << konacanRezultat << endl;

    return 0;
}