#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, long long);

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

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

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

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

/// //MAIN// ///

long long a[10005];
long long mat[1005][1005];
long long n, m;

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

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

        return sum;
    }

    for(long long i = 0; i < a[step]; ++i){
        mat[step][i] = 1;
    }
    long long x = rek(step + 1);
    for(long long i = 0; i < a[step]; ++i){
        mat[step][i] = 0;
    }
    for(long long i = 0; i < m - a[step]; ++i){
        mat[step][m - i - 1] = 1;
    }
    long long y = rek(step + 1);
    for(long long 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;
}

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

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

long long getRand(){
    return rng();
}

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

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

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

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

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

long long power(long long m_a, long long m_b, long long m_mod){
    long long 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;
}

long long power(long long m_a, long long m_b){
    long long 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;
}
//