#include <bits/stdc++.h>

using namespace std;

#define INFI 987654321
#define INFL 987654321987654321
#define MOD 1000000007

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
void read(T, int);

template<typename T>
void write(T, int);

template<typename T>
int sumFor(T, int, int);

template<typename T>
int sumFor(T, int);

int power(int, int, int);
int power(int, int);
void add(int&, int&);
int getRand();
int max(int, int, int);

/// //MAIN// ///

int a[105];
int mat[105][105];
int n, m;

int rek(int step){
    if(step == n){
        int sum = 0;
        int nop = 0;
        int nod = 0;

        for(int i = 0; i < m; ++i){
            for(int j = 0; j < n; ++j){
                if(mat[j][i] == 1){
                    nop++;
                }else{
                    nod++;
                }
            }
            sum += nop * nod;
            nop = 0;
            nod = 0;
        }

        return sum;
    }

    for(int i = 0; i < a[step]; ++i){
        mat[step][i] = 1;
    }
    int x = rek(step + 1);
    for(int i = 0; i < a[step]; ++i){
        mat[step][i] = 0;
    }
    for(int i = 0; i < m - a[step]; ++i){
        mat[step][m - i - 1] = 1;
    }
    int y = rek(step + 1);
    for(int i = 0; i < m - a[step]; ++i){
        mat[step][m - i - 1] = 0;
    }

    return min(x, y);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    read(a, n);

    cout << rek(0) << "\n";
    return 0;
}

/// /////////////////////////////////////////////

int max(int m_a, int m_b, int m_c){
    if(m_c >= m_a && m_c >= m_b){
        return m_c;
    }
    return m_a >= m_b ? m_a : m_b;
}

int getRand(){
    return rng();
}

void add(int& m_a, int& m_b){
    m_a = (m_a + m_b) % MOD;
}

template<typename T>
void write(T m_pnter, int m_size){
    for(int i = 0; i < m_size; ++i){
        cout << m_pnter[i] << " ";
    }
    cout << "\n";
}

template<typename T>
void read(T m_pnter, int m_size){
    for(int i = 0; i < m_size; ++i){
        cin >> m_pnter[i];
    }
}

template<typename T>
int sumFor(T m_pnter, int m_l, int m_r){
    int m_sum = 0;
    for(int i = m_l; i < m_r; ++i){
        m_sum += m_pnter[i];
    }
    return m_sum;
}

template<typename T>
int sumFor(T m_pnter, int m_r){
    int m_sum = 0;
    for(int i = 0; i < m_r; ++i){
        m_sum += m_pnter[i];
    }
    return m_sum;
}

int power(int m_a, int m_b, int m_mod){
    int m_res = 1;
    while(m_b > 0){
        if(m_b % 2 == 1){
            m_res = (m_res * m_a) % m_mod;
        }
        m_b /= 2;
        m_a = (m_a * m_a) % m_mod;
    }
    return m_res;
}

int power(int m_a, int m_b){
    int m_res = 1;
    while(m_b > 0){
        if(m_b % 2 == 1){
            m_res = m_res * m_a;
        }
        m_b /= 2;
        m_a = m_a * m_a;
    }
    return m_res;
}