#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint2 = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;
//const Int mod = 998244353;

typedef struct {
    int64_t to, weight;
} edge;

Int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};
Int dy[] = {1, 0, -1, 0, -1, -1, 1, 1};

template<class T> 
istream &operator>>(istream &is, vector<T> &v) { 
    for (auto &e : v) {
        is >> e; 
    }
    return is; 
}

bool print_space_enable = false;
void print() { 
    std::cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    std::cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

template<class T>
vector<T> make_vec(size_t n, T val) {
    return vector<T>(n, val);
}

template<class... Ts>
auto make_vec(size_t n, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}

bool is_overflow(Int a, Int b) {
    return a > INF / b;
}

void solve() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    cin >> a;
    vector<Int> b = a;
    for (Int i = 0; i + 1 < n; i++) {
        b[i + 1] += b[i];
    }
    for (Int i = 0; i + 1 < n; i++) {
        b[i + 1] += b[i];
    }
    vector<Int> c = a;
    for (Int i = 0; i + 1 < n; i++) {
        c[i + 1] = max(c[i], c[i + 1]);
    }
    for (Int i = 0; i < n; i++) {
        print(b[i] + (i + 1) * c[i]);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    //Int _t; cin >> _t; while (_t--) solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> V(N, 0);
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    V.at(A)++;
  }
  int ans = 0, X = V.at(0);
  for (int i = 0; i < N; i++) {
    X = min(K,min(X, V.at(i)));
    ans += X;
  }
  cout << ans << endl;
}