#include <bits/stdc++.h>
using namespace std;
int n,k,a[1010],max1,t,max2;
int main()
{
cin >> n >> k;
for(int i = 0;i < n;i++)
{
cin >> a[i];
if(a[i] > max1) max1 = a[i];
}
sort(a,a + n);
for(int i = max1;i >= 1;i--)
{
t = 0;
for(int j = 0;j < n;j++)
{
if(a[j] >= i - 1 && a[j] <= i) t += a[j];
}
if(t > max2) max2 = t;
}
cout << max2;
return 0;
}