#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define vt vector
#define heap priority_queue
#define dq deque
#define maxN 100005
#define maxM 5005
#define pb push_back
#define pf push_front
#define inf 1000000007 // mod for some cases
void io() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
typedef long long ll;
typedef pair<ll, ll> ii;
//type_here
ll n, m, res, cnt, d, ans, t, f[maxM][205], s[maxM][205], a[maxN], k;
void solve()
{
    cin>>n>>k;
    for (int i=1;i<=n;i++) cin>>a[i];
    f[0][1] = 0;
    for (int i=1;i<=n;i++)
    {
        f[i][1] = f[i-1][1] + a[i];
        s[i][1] = 0;
    }
    /* f[i][j] (tổng của cái dãy số tính tới hiện tại nếu chưa cắt) và s[i][j] 
    (là tổng từ cái phần tử trước phần tử được cắt gần nhất tới ptu đầu đã được tối ưu)*/
    for (int i = 2;i<=n;i++)
    {
        for (int j = 2;j<=min(i*1ll, k+1);j++)
        {
            ll no_updated = f[i-1][j] + s[i-1][j] + a[i]; // vẫn giữ nguyên, nối tiếp với đoạn lúc trước (cắt bắt đầu từ một phần tử trước đó)
            ll updated = round(f[i-1][j-1]/float(10))*10 + s[i-1][j-1] + a[i]; //phần tử hiện tại sẽ là phần tử đầu tiên trong đoạn cắt mới
            if (no_updated<=updated&&(j<=i-1))
            {
                s[i][j] = s[i-1][j];
                f[i][j] = f[i-1][j] + a[i];
            }
            else
            {
                s[i][j] = s[i-1][j-1] + round(f[i-1][j-1]/float(10))*10;
                f[i][j] = a[i];
            }
        }
    }
    res = inf;
    for (int i=1;i<=k+1;i++)
    {
        ll t = round(f[n][i]/float(10))*10;
        res = min(res, t + s[n][i]);
    }
    cout<<res<<endl;
}
signed main()
{
    io();
    solve();
    return 0;
}
