#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,m;
  cin>>n>>m;
  priority_queue<Int,vector<Int>,greater<Int> > q;
  for(Int i=0;i<n;i++){
    Int c;
    cin>>c;
    q.emplace(c);
  }
  while(m--){
    Int s=q.top();q.pop();
    if(s-1) q.emplace(s-1);
  }
  cout<<n-q.size()<<endl;
  return 0;
}