#include <iostream>
#include <cmath>

using namespace std;

int levo(int f)
{
    int p=0;
    while(f != 0)
    {
        p=p*10+1;
        f--;
    }
    return p;
}

int proi(int g,int h)
{
    int s=0;
    while(g != 0)
    {
        s+=(g%10)*(h - (g%10));
        g/=10;
    }
    return s;
}

int power(int q,int w)
{
    int t=1;
    for(int i=0;i<w;i++)
        t*=q;
    return t;
}

int main()
{
    int n,m,i,k,l,c;
    cin >> n >> m;
    int a[n];
    for(i=0;i<n;i++)
        cin >> a[i];
    c = m - a[0];
    k = levo(a[0])*power(10,c);
    for(i=1;i<n;i++)
    {
        l = levo(a[i])*pow(10,m-a[i]);
        if(proi(k+l,i+1) > proi(k+levo(m - a[i]),i+1))
            k += levo(m - a[i]);
        else
            k += l;
    }
    cout << proi(k,n);
    return 0;
}