// Starcraft 2 enjoyer //
#include <bits/stdc++.h>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
#define LSOne(X) ((X) & -(X))
const int N = 1e5 + 5;
const int K = 1e2 + 5;
const int M = 2e5 + 5;
const int LG = 20;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 998244353;
int n, k, a[N];
vector<pair<int, long long>> best[K];
map<long long, int> mp[K];
inline void solve()
{
cin >> n >> k;
for (int x = 1; x <= n; x++)
{
cin >> a[x];
}
best[0].push_back({0, 0});
mp[0][0]++;
a[0] = 0;
for (int x = 1; x <= n; x++)
{
for (int y = k; y >= 0; y--)
{
long long mn = INF;
while (!best[y].empty())
{
if (best[y].back().first <= a[x])
{
mn = min(mn, best[y].back().second);
long long i = best[y].back().first + best[y].back().second;
mp[y][i]--;
if (mp[y][i] == 0)
mp[y].erase(i);
best[y].pop_back();
}
else
{
break;
}
}
if (!best[y].empty())
{
mn = min(mn, mp[y].begin()->first - a[x]);
}
if (mn == INF)
{
continue;
}
mp[y][mn + a[x]]++;
best[y].push_back({a[x], mn});
best[y + 1].push_back({0, mn + a[x]});
mp[y + 1][mn + a[x]]++;
}
}
cout << mp[k].begin()->first;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
for (int x = 1; x <= t; x++)
{
solve();
}
return 0;
}