#include<iostream>
#include<algorithm>
#include<cmath>
#include<string.h>
#include<cstring>
#include<string>
typedef long long ll;
using namespace std;
const int MAX=0x3f3f3f;
const int MIN=-0x3f3f3f;
const int N=3e5+5;
ll a[N];
ll cnt[N];

int main()
{
	int n,k;
	cin >> n >> k;
	ll minc=MAX;
	ll maxc=MIN;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		cnt[a[i]]++;
		//maxc=max(maxc,cnt[a[i]]);
		//minc=min(minc,cnt[a[i]]);
	}
	ll res=0;
	if(cnt[0]!=0){
		while(k--){
			int i=0;
			while(cnt[i]){
				cnt[i]--;
				i++;
			}
			if(i){
				res=res+i;
			}
		}
	}
	cout << res <<endl; 
	return 0;
 } 
#include <bits/stdc++.h>

using namespace std;
enum Direction{
  	BACKWARD,
  	FORWARD,
  	UNDIRECTED
};
struct Edge{
  	int v, u, direction;
  	int other(int x){
      if(x == u)
        return v;
       return u;
    }
  	void set_source(int x){
    	if(x == u)
          direction = FORWARD;
      	else
          direction = BACKWARD;
    }
};

void dfs(int node, vector<bool>& vis, vector<vector<int>>& adj, vector<Edge>& edges, vector<int>& c){
  vis[node] = true;
  for(auto out : adj[node]){
    int ne = edges[out].other(node);
    if(c[node] == c[ne]){
      if(edges[out].direction == UNDIRECTED)
        edges[out].set_source(node);
      if(!vis[ne]){ // forward edge
        dfs(ne, vis, adj, edges, c);
      }
    }
  }
}

void solve(vector<vector<int>>& adj, vector<Edge>& edges, vector<int>& c){
	int n = adj.size();
  	for(auto &edge : edges){
    	if(c[edge.v] < c[edge.u])
        	edge.direction = FORWARD;
     	else if(c[edge.v] > c[edge.u])
         	edge.direction = BACKWARD;
    }
  	vector<bool> vis(n);
  	for(int i = 0;i < (int)adj.size();i++){
      if(!vis[i])
	      dfs(i, vis, adj, edges, c);
    }
}

int main(){
	int n, m;
  	cin >> n >> m;
  	vector<vector<int>> adj(n);
  	vector<Edge> edges(m); 
  	vector<int> c(n);
  	for(int i = 0;i < m;i++){
      cin >> edges[i].u >> edges[i].v;
      edges[i].u -= 1;
      edges[i].v -= 1;
      edges[i].direction = UNDIRECTED;
      adj[edges[i].u].push_back(i);
      adj[edges[i].v].push_back(i);
    }
  	for(int i = 0;i < n;i++){
    	cin >> c[i];
    }
  	solve(adj, edges, c);
  	for(int i = 0;i < (int)edges.size();i++){
      if(edges[i].direction == FORWARD)
        cout << "->\n";
      else if(edges[i].direction == BACKWARD)
        cout << "<-\n";
    }
  return 0;
}
