///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n, k, a , mn = INT_MAX , mx = INT_MIN ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        mx = max( mx , a ) ;
        mn = min( mn , a ) ;
        Mp[ a ] ++ ;
    }

    ll sum = 0, cnt = 0 ;
    for( int i = mx ; i > mn ; i -- )
    {
        sum += Mp[i ] ;
        if( sum == k )
        {
            sum = 0 ;
            Mp[ i - 1 ] += Mp[ i ] ;
        }
        else if( sum > k )
        {
            cnt ++ ;
            sum = Mp[ i ] ;
        }
        Mp[ i - 1 ] += Mp[ i ] ;
    }

    if( sum > 0 )
    {
        cnt ++ ;
    }
    cout << cnt << endl ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st[ 30 ] ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n , k , a ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        v.pb( a ) ;
    }

    sort( all( v ) ) ;
    v1 = v ;
    Unique( v1 ) ;
    int j = 1 ;
    for( int i = 0 ; i < n ; i ++ )
    {
        if( v1[ j ] == v[ i ] )
        {
            stk.push( n - i ) ;
            j ++ ;
        }
    }

    int cnt = 0 , sum = 0 ;
    while( !stk.empty() )
    {
        sum += stk.top() ;
        if( sum == k )
        {
            cnt ++ ;
            sum = 0 ;
        }
        else if( sum > k )
        {
            cnt ++ ;
            sum = stk.top() ;
        }
        stk.pop() ;
    }

    if( sum != 0 )
    {
        cnt ++ ;
    }

    cout << cnt << endl ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n, k, a ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        v.pb( a ) ;
    }

    sort( all( v ) ) ;
    v1 = v ;
    Unique( v1 ) ;

    int j = 1 ;
    for( int i = 0 ; i < n && j < v1.size() ; i ++ )
    {
        if( v1[ j ] == v[ i ] )
        {
            stk.push( n - i ) ;
            j ++ ;
        }
    }

    ll cnt = 0, sum = 0 ;
    while( !stk.empty() )
    {

        if( sum + stk.top()<=k)
        {
            sum+=stk.top();
        }
        else
        {
            sum=stk.top();
            cnt++;
        }
        stk.pop() ;
    }

    if( sum != 0 )
    {
        cnt ++ ;
    }

    cout << cnt << endl ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st[ 30 ] ;
deque < ll > dq ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

ll n , k , a ;
void bsearch( ll low , ll high )
{
    ll mid , ans = 0 ;
    while( low <= high )
    {
        mid = ( low + high ) / 2 ;
        ll sum = 0 , cnt = 0 ;
        for( auto x : v )
        {
            if( x > mid )
            {
                cnt ++ ;
                sum += ( x - mid ) ;
            }
        }
        if( sum <= k )
        {
            ans = cnt ;
            high = mid - 1 ;
        }
        else
        {
            low = mid + 1 ;
        }
    }
    cout << ans << endl ;
}

int main()
{
    CIN ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        v.pb( a ) ;
    }

    bsearch( 0 , 2000000 ) ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st[ 30 ] ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n , k , a ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        v.pb( a ) ;
    }

    sort( all( v ) ) ;
    v1 = v ;
    Unique( v1 ) ;
    int j = 1 ;
    for( int i = 0 ; i < n ; i ++ )
    {
        if( v1[ j ] == v[ i ] )
        {
            stk.push( n - i ) ;
            j ++ ;
        }
    }

    int cnt = 0 , sum = 0 ;
    while( !stk.empty() )
    {
        sum += stk.top() ;
        if( sum > k )
        {
            cnt ++ ;
            sum = stk.top() ;
        }
        stk.pop() ;
    }

    if( sum != 0 )
    {
        cnt ++ ;
    }

    cout << cnt << endl ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n, k, a , mn = INT_MAX , mx = INT_MIN ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        mx = max( mx , a ) ;
        mn = min( mn , a ) ;
        Mp[ a ] ++ ;
    }

    ll sum = 0, cnt = 0 ;
    for( int i = mx ; i > mn ; i -- )
    {
        sum += Mp[ i ] ;
        if( sum == k )
        {
            cnt ++ ;
            sum = 0 ;
        }
        else if( sum > k )
        {
            cnt ++ ;
            sum = Mp[ i ] ;
        }
        Mp[ i - 1 ] += Mp[ i ] ;
    }

    if( sum > 0 )
    {
        cnt ++ ;
    }
    cout << cnt << endl ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st[ 30 ] ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n , k , a ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        v.pb( a ) ;
    }

    sort( all( v ) ) ;
    v1 = v ;
    Unique( v1 ) ;
    int j = 1 ;
    for( int i = 0 ; i < n && j < v1.size() ; i ++ )
    {
        if( v1[ j ] == v[ i ] )
        {
            stk.push( n - i ) ;
            j ++ ;
        }
    }

    ll cnt = 0 , sum = 0 ;
    while( !stk.empty() )
    {
        //cout << stk.top() << endl ;
        sum += stk.top() ;
        if( sum == k )
        {
            cnt ++ ;
            sum = 0 ;
        }
        else if( sum > k )
        {
            cnt ++ ;
            sum = stk.top() ;
        }
        stk.pop() ;
    }

    if( sum != 0 )
    {
        cnt ++ ;
    }

    cout << cnt << endl ;

    return 0 ;
}


///...................................*****.................................................///
///                  Mujahidul Islam ( mujahidulislam2923@gmail.com )                       ///
///                  Department of Ict                                                      ///
///                  Comilla University , Bangladesh.                                       ///
///...................................*****.................................................///

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define          CIN                    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define          ll                     long long int
#define          ull                    unsigned long long int
#define          pii                    pair < int, int>
#define          pll                    pair < ll, ll>
#define          MOD                    1000000007
#define          vi                     vector<int>
#define          vl                     vector<ll>
#define          pb                     push_back
#define          sc                     scanf
#define          pf                     printf
#define          scin(x)                scanf("%d",&(x))
#define          scin2(x,y)             scanf("%d %d",&(x),&(y))
#define          scln(x)                scanf("%lld",&(x))
#define          scln2(x,y)             scanf("%lld %lld",&(x),&(y))
#define          min3(a,b,c)            min(a,min(b,c))
#define          min4(a,b,c,d)          min(d,min(a,min(b,c)))
#define          max3(a,b,c)            max(a,max(b,c))
#define          max4(a,b,c,d)          max(d,max(a,max(b,c)))
#define          ms(a,b)                memset(a,b,sizeof(a))
#define          mp                     make_pair
#define          gcd(a, b)              __gcd(a,b)
#define          lcm(a, b)              ((a)*(b)/gcd(a,b))
#define          input                  freopen("input.txt","rt", stdin)
#define          output                 freopen("output.txt","wt", stdout)
#define          PI                     3.141592653589793238462643
#define          zero(a)                memset(a,0,sizeof a)
#define          all(v)                 v.begin(),v.end()
#define          Max(v)                 *max_element(all(v))
#define          Upper(c,x)             (upper_bound(c.begin(),c.end(),x)-c.begin())
#define          Lower(c,x)             (lower_bound(c.begin(),c.end(),x)-c.begin())
#define          Unique(X)              (X).erase(unique(all(X)),(X).end())

///priority_queue<int,vector<int>,greater<int> >pq;
///string str = "abcdefghijklmnopqrstuvwxyz";
///string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

///---------------Order set-------------------
///template<typename T> using orderset =tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///#include <ext/pb_ds/assoc_container.hpp>
///using namespace __gnu_pbds;
///*os.find_by_order(index) os.order_of_key(value)

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------
///sort( all( v ) ) ;

vl v, v1, v2 ;
vector < pll > vec1, vec2 ;
map < ll, ll > Mp ;
set < ll > st ;
deque < ll > dq ;
stack < ll > stk ;
multiset < ll > S ;
multiset < ll > :: iterator it ;

int main()
{
    CIN ;
    ll n, k, a ;
    cin >> n >> k ;
    for( int i = 0 ; i < n ; i ++ )
    {
        cin >> a ;
        v.pb( a ) ;
        v1.pb( a ) ;
    }

    sort( all( v ) ) ;
    sort( all( v1 ) ) ;
    Unique( v1 ) ;
    int j = 1 ;
    for( int i = 0 ; i < n && j < v1.size() ; i ++ )
    {
        if( v1[ j ] == v[ i ] )
        {
            stk.push( n - i ) ;
            j ++ ;
        }
    }

    ll cnt = 0, sum = 0 ;
    while( !stk.empty() )
    {
        // cout << stk.top() << endl ;
        sum += stk.top() ;
        if( sum > k )
        {
            cnt ++ ;
            sum = stk.top() ;
        }
        stk.pop() ;
    }

    if( sum != 0 )
    {
        cnt ++ ;
    }

    cout << cnt << endl ;

    return 0 ;
}

/*
10 10
1 1 2 2 2 3 4 4 5 5
*/


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[1];i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
        else
            if (sum+f[i]==k)
        {
            dem++;
            sum=0;
        }
        else sum=sum+f[i];
    }
    cout<<dem;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
   // freopen("a.inp","r",stdin);
   // freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[1]+1;i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
//            if (sum+f[i]==k)
//        {
//            dem++;
//            sum=0;
//        }
        else sum=sum+f[i];
    }
    if (h[n]==1) cout<<dem;else cout<<dem+1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[20007];
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=n;i>=1;i--)
    {
        if (h[i]!=h[i+1])
        {
        f[h[i]]+=f[h[i+1]];
        if (sum+f[h[i]]>k)
        {
            dem++;
            sum=f[h[i]];
        }
        else sum=sum+f[h[i]];
        }
    }
    cout<<dem;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[1];i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
        else sum=sum+f[i];
    }
    cout<<dem;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=n;i>=1;i--)
    {
        if (h[i]!=h[i+1])
        {
        f[h[i]]+=f[h[i+1]];
        if (sum+f[h[i]]>k)
        {
            dem++;
            sum=f[h[i]];
        }
        else sum=sum+f[h[i]];
        }
    }
    cout<<dem;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[1]+1;i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
//            if (sum+f[i]==k)
//        {
//            dem++;
//            sum=0;
//        }
        else sum=sum+f[i];
    }
    cout<<dem+1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[2];i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
//            if (sum+f[i]==k)
//        {
//            dem++;
//            sum=0;
//        }
        else sum=sum+f[i];
    }
    cout<<dem+1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
    //freopen("a.inp","r",stdin);
    //freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[2];i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
        else
            if (sum+f[i]==k)
        {
            dem++;
            sum=0;
        }
        else sum=sum+f[i];
    }
    cout<<dem+1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int h[200007];
int cnt=0;
int f[200007];
int main()
{
   // freopen("a.inp","r",stdin);
   // freopen("a.out","w",stdout);
    int n,k;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
        f[h[i]]++;
    }
    int dem=0;
    int sum=0;
    sort(h+1,h+n+1);
    f[h[n]+1]=0;
    for (int i=h[n];i>=h[1]+1;i--)
    {
        f[i]+=f[i+1];
        if (sum+f[i]>k)
        {
            dem++;
            sum=f[i];
        }
//            if (sum+f[i]==k)
//        {
//            dem++;
//            sum=0;
//        }
        else sum=sum+f[i];
    }
    if (h[n]==h[1]) cout<<dem;else cout<<dem+1;
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i > mn; i--)
    {
        freq[i] += 2*freq[i + 1];
        if(freq[i] >= k) freq[i] -= k, ans++;
        else if(i == mn + 1 and freq[i] > 0) freq[i]-=k, ans++;
    }
    if(freq[mn + 1] > 0) ans++;
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i >= mn; i--)
    {
        freq[i] += 2*freq[i + 1];
        if(freq[i] > k and i != mn) freq[i + 1] = 0, ans++;
        else if(i == mn and freq[i + 1] > 0) freq[i + 1] = 0, ans++;
    }
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, mn = 1e17;
    cin >> n >> k;
    rep(i,1,n) cin >> h[i], mn = min(mn, h[i]);
    ll temp = 0;
    for(int i = 200000; i > mn; i--)
    {
        if(temp + h[i] <= k) temp += h[i];
        else ans++, temp = h[i];
    }
    if(temp > 0) ans++;
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i >= mn; i--)
    {
        if(freq[i] + 2*freq[i + 1] > k and i != mn)  ans++,  freq[i] += freq[i + 1];
        else if(i == mn and freq[i + 1] > 0) {
            ans++;
            break;
        }
        else freq[i] += 2*freq[i + 1];
    }
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i > mn; i--)
    {
        freq[i] += 2*freq[i + 1];
        if(freq[i] >= k) freq[i] -= k, ans++;
        else if(i == mn + 1 and freq[i] > 0) freq[i]-=k, ans++;
    }
    if(freq[mn + 1] > 0) ans++;
    cout << ans;
}
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i > mn; i--)
    {
        freq[i] += 2*freq[i + 1];
        if(freq[i] >= k) freq[i] -= k, ans++;
        else if(i == mn + 1 and freq[i] > 0) freq[i]-=k, ans++;
    }
    if(freq[mn + 1] > 0) ans++;
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200003
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0;
    cin >> n >> k;
    rep(i,1,n) cin >> h[i];
    sort(h + 1, h + 1 + n);
    for(int i = n; i >= 1; i--)
    {
        freq[i] = freq[i + 1] + h[i];
    }
    ll p = 1, q = n;
    while(1)
    {
        ll  temp, flag = 0;
        while(p <= q)
        {
            ll mid = (p + q)/2;
            if(freq[mid] - (h[mid] * (n - mid + 1)) <= k) q = mid - 1, flag = 1;
            else p = mid + 1;
        }
        if(flag == 0) break;
        if(freq[p] - (h[p] * (n - p + 1)) == 0) break;
        ans++;
        for(int i = p; i <= n; i++) h[i] = h[p];
        for(int i = n; i >= 1; i--) freq[i] = freq[i + 1] + h[i];
        q = p; p = 1;
    }
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i >= mn; i--)
    {
        if(freq[i] + 2*freq[i + 1] > k and i != mn) freq[i + 1] = 0, ans++;
        else if(i == mn and freq[i + 1] > 0) freq[i + 1] = 0, ans++;
        freq[i] += 2*freq[i + 1];
    }
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    ll temp = 0;
    for(int i = 200000; i > mn; i--)
    {
        h[i] += h[i + 1];
        if(temp + h[i] <= k) temp += h[i];
        else ans++, temp = h[i];
    }
    if(temp > 0) ans++;
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    for(int i = 200000; i >= mn; i--)
    {
        if(freq[i] + 2*freq[i + 1] > k and i != mn)  ans++,  freq[i] += freq[i + 1];
        else if(i == mn and freq[i + 1] > 0) ans++;
        else freq[i] += 2*freq[i + 1];
    }
    cout << ans;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define ff first
#define ss second
#define mx 200002
using namespace std;
ll h[mx], freq[mx];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k, ans = 0, p = 0, mn = 1e17;
    cin >> n >> k;
    memset(freq, 0, sizeof(freq));
    rep(i,1,n) cin >> h[i], freq[h[i]]++, mn = min(mn, h[i]);
    ll temp = 0;
    for(int i = 200000; i > mn; i--)
    {
        freq[i] += freq[i + 1];
        if(temp + freq[i] <= k) temp += freq[i];
        else ans++, temp = freq[i];
    }
    if(temp > 0) ans++;
    cout << ans;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	int H = 0,need = maxn;
	for(int i = 0; i < n; i++) {
		int x; scanf("%d",&x);
		c[x]++;
		H = max(H, x);
		need = min(need, x);
	}
	int ans = 0;
	ll sum = 0,C = 0;
	for(int i = H; i > need; i--) {
		C += c[i];
		if(sum + C > k) {
			ans++;
			sum = C;
			continue;
		}
		sum += C;
	}
	if(H != need)ans++;
	printf("%d\n",ans);
	return 0;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	int H = 0,need = maxn * 2;
	for(int i = 0; i < n; i++) {
		int x; scanf("%d",&x);
		c[x]++;
		H = max(H, x);
		need = min(need, x);
	}
	int ans = 0;
	ll sum = 0,C = 0;
	for(int i = H; i > need; i--) {
		C += c[i];
		if(sum + C > k) {
			ans++;
			sum = C;
			continue;
		}
		sum += C;
	}
	if(H != need) ans++;
	printf("%d\n",ans);
	return 0;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int h[maxn * 2],c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i = 0; i < n; i++)
		scanf("%d",h + i);
	h[n++] = 0;
	sort(h,h + n);
	int m = 1;
	c[0] = 0;
	for(int i = 1; i < n; i++) {
		if(h[i] == h[i - 1]) c[m - 1]++;
		else {
			h[m++] = h[i];
			c[m - 1] = 1;
		}
	}
	int ans = 0;
	for(int i = m - 1; i > 1; i--) {
		ll sum = 0,C = 0;
		h[i + 1] = h[i];
		int j = i;
		while(j) {
			if(C * (h[j + 1] - h[j]) + sum > k) break;
			sum += C * (h[j + 1] - h[j]);
			C += c[j];
			j--;
		}
		if(j == 0) {
			if(sum) ans++;
			break;
		}
		if(sum) {
			int left = k - sum;
			int dec = left / C;
			if(sum > 0) ans++;
			h[j + 1] -= dec;
			c[j + 1] = C;
		}
		int cut = k / c[j + 1];
		ans += (h[j + 1] - h[j]) / cut;
		h[j + 1] = h[j] + (h[j + 1] - h[j]) % cut;
		if(j == 1) {
			ans += (h[j] != h[j + 1]);
			break;
		}
		if(h[j + 1] != h[j]) i = j + 2;
		else {
			i = j + 1;
			c[j] += c[j + 1];
		}
	}
	printf("%d\n",ans);
	return 0;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int h[maxn * 2],c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i = 0; i < n; i++)
		scanf("%d",h + i);
	h[n++] = 0;
	sort(h,h + n);
	int m = 1;
	c[0] = 1;
	for(int i = 1; i < n; i++) {
		if(h[i] == h[i - 1]) c[m - 1]++;
		else {
			h[m++] = h[i];
			c[m - 1] = 1;
		}
	}
	int ans = 0;
	for(int i = m - 1; i > 1; i--) {
		ll sum = 0,C = 0;
		h[i + 1] = h[i];
		int j = i;
		while(j) {
			if(C * (h[j + 1] - h[j]) + sum > k) break;
			sum += C * (h[j + 1] - h[j]);
			C += c[j];
			j--;
		}
		int left = k - sum;
		int dec = left / C;
		if(sum > 0) ans++;
		h[j + 1] -= dec;
		c[j + 1] = C;
		int cut = k / c[j + 1];
		ans += (h[j + 1] - h[j]) / cut;
		h[j + 1] = h[j] + (h[j + 1] - h[j]) % cut;
		if(h[j + 1] != h[j]) i = j + 2;
		else {
			i = j + 1;
			c[j] += c[j + 1];
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
1 2 3 4 10
1 2 3 4 5
1 2 3 3 3
1 2 2 2 2

 * */


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	int H = 0,need = maxn;
	for(int i = 0; i < n; i++) {
		int x; scanf("%d",&x);
		c[x]++;
		H = max(H, x);
		need = min(need, x);
	}
	int ans = 0;
	ll sum = 0,C = 0;
	for(int i = H; i > need; i--) {
		C += c[i];
		if(sum + C > k) {
			ans++;
			sum = C;
			continue;
		}
		sum += C;
	}
	ans++;
	printf("%d\n",ans);
	return 0;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int h[maxn * 2],c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i = 0; i < n; i++)
		scanf("%d",h + i);
	h[n++] = 0;
	sort(h,h + n);
	int m = 1;
	c[0] = 0;
	for(int i = 1; i < n; i++) {
		if(h[i] == h[i - 1]) c[m - 1]++;
		else {
			h[m++] = h[i];
			c[m - 1] = 1;
		}
	}
	int ans = 0;
	for(int i = m - 1; i > 1; i--) {
		ll sum = 0,C = 0;
		h[i + 1] = h[i];
		int j = i;
		while(j) {
			if(C * (h[j + 1] - h[j]) + sum > k) break;
			sum += C * (h[j + 1] - h[j]);
			C += c[j];
			j--;
		}
		if(sum) {
			int left = k - sum;
			int dec = left / C;
			if(sum > 0) ans++;
			h[j + 1] -= dec;
			c[j + 1] = C;
		}
		int cut = k / c[j + 1];
		ans += (h[j + 1] - h[j]) / cut;
		h[j + 1] = h[j] + (h[j + 1] - h[j]) % cut;
		if(j == 1) {
			ans += (h[j] != h[j + 1]);
			break;
		}
		if(h[j + 1] != h[j]) i = j + 2;
		else {
			i = j + 1;
			c[j] += c[j + 1];
		}
	}
	printf("%d\n",ans);
	return 0;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int h[maxn * 2];

bool check() {
	for(int i = 1; i < n; i++)
		if(h[i] != h[i - 1])
			return false;
	return true;
}

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	int last = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d",h + i);
		last = max(last, h[i]);
	}
	int ans = 0;
	int c = 0;
	while(!check()) {
		int l = 0,r = last;
		while(r - l > 1) {
			int mid = (l + r) >> 1;
			ll cnt = 0;
			for(int i = 0; i < n; i++)
				if(h[i] > mid)
					cnt += h[i] - mid;
			if(cnt > k) l = mid;
			else r = mid;
		}
		last = r + 1;
		ans++;
		for(int i = 0; i < n; i++)
			if(h[i] > r)
				h[i] = r;
	}
	printf("%d\n",ans);
	return 0;
}


/*-----------------------------------------------
*	Filename: C.cpp
*	Author: zhuyutian
*	Date: 2018.10.22
-----------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define mpii(a, b) make_pair(a, b)
const int maxn = 100005;
const int INF = 1 << 30;
const double eps = 1e-6;
const int mod = 1000000007;

int n,k;
int h[maxn * 2],c[maxn * 2];

int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	scanf("%d%d",&n,&k);
	for(int i = 0; i < n; i++)
		scanf("%d",h + i);
	h[n++] = 0;
	sort(h,h + n);
	int m = 1;
	c[0] = 1;
	for(int i = 1; i < n; i++) {
		if(h[i] == h[i - 1]) c[m - 1]++;
		else {
			h[m++] = h[i];
			c[m - 1] = 1;
		}
	}
	int ans = 0;
	for(int i = m - 1; i > 1; i--) {
		ll sum = 0,C = 0;
		h[i + 1] = h[i];
		int j = i;
		while(j) {
			if(C * (h[j + 1] - h[j]) + sum > k) break;
			sum += C * (h[j + 1] - h[j]);
			C += c[j];
			j--;
		}
		if(sum) {
			int left = k - sum;
			int dec = left / C;
			if(sum > 0) ans++;
			h[j + 1] -= dec;
			c[j + 1] = C;
		}
		int cut = k / c[j + 1];
		ans += (h[j + 1] - h[j]) / cut;
		h[j + 1] = h[j] + (h[j + 1] - h[j]) % cut;
		if(h[j + 1] != h[j]) i = j + 2;
		else {
			i = j + 1;
			c[j] += c[j + 1];
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
1 2 3 4 10
1 2 3 4 5
1 2 3 3 3
1 2 2 2 2

 * */


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	long long n, m;
	cin >> n >> m;
	long long Min = 1000000009, Max = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		Min = min(Min, a[i]);
		Max = max(Max, a[i]);
	}
	long long l = Min, r = Max;
	if (l == r) {
		cout << 0;
		return 0;
	}
	int count = 0;
	long long ans = 0;
	while (1) {
		l = Min;
		while (l < r) {
			long long mid = (l + r) / 2;
			long long t = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] > mid)t += a[i] - mid;
			}
			if (t <= m) {
				r = mid - 1;
			}
			else l = mid + 1;
		}
		long long t = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > r)t += a[i] - r;
		}
		if (t > m)r++;
		ans++;
		if (Min == r) {
			cout << ans;
			return 0;
		}
		for (int i = 0; i < n; i++) {
			if (a[i] > r)a[i] = r;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	int count2 = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			sum += count2;
			count2 += a[i + 1];
		}
		if (sum > m) {
			count++;
			sum = count2;
			count2 = 0;
		}
		if (i == MIN) {
			count++;
			break;
		}
	}
	cout << count;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	long long n, m;
	cin >> n >> m;
	long long Min = 1000000009, Max = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		Min = min(Min, a[i]);
		Max = max(Max, a[i]);
	}
	long long l = Min, r = Max;
	if (l == r) {
		cout << 0;
		return 0;
	}
	int count = 0;
	long long ans = 0;
	while (1) {
		l = Min;
		while (l <= r) {
			long long mid = (l + r) / 2;
			long long t = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] > mid)t += a[i] - mid;
			}
			if (t <= m) {
				r = mid - 1;
			}
			else l = mid + 1;
		}
		ans++;
		if (Min == l) {
			cout << ans;
			return 0;
		}
		for (int i = 0; i < n; i++) {
			if (a[i] > r)a[i] = l;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			if (sum > m) {
				sum = a[i+1];
				count++;
			}
			a[i] += a[i + 1];
			a[i + 1] = 0;
		}
		if (i == MIN-1) {
			if (a[i] + a[i + 1] > m) {
				count++;
			}
			break;
		}
	}
	cout << count;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	long long n, m;
	cin >> n >> m;
	long long Min = 1000000009, Max = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		Min = min(Min, a[i]);
		Max = max(Max, a[i]);
	}
	long long l = Min, r = Max;
	if (l == r) {
		cout << 0;
		return 0;
	}
	int count = 0;
	long long ans = 0;
	long long mem = r;
	while (1) {
		l = Min;
		while (l <= r) {
			long long mid = (l + r) / 2;
			long long t = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] > mem)a[i] = mem;
				if (a[i] > mid)t += a[i] - mid;
			}
			if (t <= m) {
				r = mid - 1;
			}
			else l = mid + 1;
		}
		ans++;
		if (Min == l) {
			cout << ans;
			return 0;
		}
		mem = l;
	}
}


#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
multiset<long long> s;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	long long n, m;
	cin >> n >> m;
	long long t;
	long long Min = 10000000009,Max = 0;
	for (int i = 0; i < n; i++) {
		cin >> t;
		Min = min(Min, t);
		Max = max(Max, t);
		s.insert(t);
	}
	long long l = Min, r = Max;
	if (l == r) {
		cout << 0;
		return 0;
	}
	long long ans = 0;
	while (1) {
		l = Min;
		while(l<=r){
			long long mid = (l + r) / 2;
			long long t = 0;
			for (multiset<long long>::reverse_iterator it = s.rbegin(); it != s.rend(); it++) {
				if (*it > mid) {
					t += (*it) - mid;
				}
				else break;
			}
			if (t <= m)r = mid - 1;
			else l = mid + 1;
		}
		ans++;
		if (Min == l) {
			cout << ans;
			return 0;
		}
		for (multiset<long long>::reverse_iterator it = s.rbegin(); it != s.rend(); it++) {
			if (*it > l) {
				s.erase(*it);
				s.insert(l);
			}
			else break;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			if (sum > m) {
				sum = a[i+1];
				count++;
			}
			a[i] += a[i + 1];
		}
		if (MIN - 1 == i) {
			if (sum - a[i + 1] > 0) count += 1;
			break;
		}
	}
	cout << count;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	long long n, m;
	cin >> n >> m;
	long long Min = 1000000009,Max=0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		Min = min(Min, a[i]);
		Max = max(Max, a[i]);
	}
	long long l = Min, r = Max;
	if (l == r) {
		cout << 0;
		return 0;
	}
	int count = 0;
	long long ans = 0;
	while (1) {
		l = Min;
		while (l < r) {
			long long mid = (l + r) / 2;
			long long t = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] > m)t += a[i] - m;
			}
			if (t <= mid) {
				r = mid - 1;
			}
			else l = mid + 1;
		}
		long long t = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] > r)t += a[i] - r;
		}
		if (t > m)r++;
		ans++;
		if (Min == r) {
			cout << ans;
			return 0;
		}
		for (int i = 0; i < n; i++) {
			if (a[i] > r)a[i] = r;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			if (sum >= m) {
				sum = a[i+1];
				count++;
			}
			a[i] += a[i + 1];
			a[i + 1] = 0;
		}
		if (MIN - 1 == i) {
			break;
		}
	}
	cout << count;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			if (sum > m) {
				sum = a[i+1];
				count++;
			}
			a[i] += a[i + 1];
		}
		if (MIN - 1 == i) {
			if (sum - a[i + 1] > a[i + 1]) count += 1;
			break;
		}
	}
	cout << count;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> a[i];
	int count = 0;
	sort(a, a + n);

	while (true) {
		long long l = 1, r = 200000;
		long long temp;
		while (l <= r) {
			long long mid = (l + r) / 2;
			long long sum = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] > mid) {
					sum += a[i] - mid;
				}
			}
			if (sum <= m){
				r = mid - 1;
			}
			else l = mid + 1;
			temp = sum;
		}
		m += temp;
		count++;
		if (l <= a[0]) {
			cout << count;
			return 0;
		}
	}
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			if (sum > m) {
				sum = a[i+1];
				count++;
			}
			a[i] += a[i + 1];
			a[i + 1] = 0;
		}
		if (i == MIN-1) {
			break;
		}
	}
	cout << count;
}


#include <iostream>
#include <algorithm>
using namespace std;
long long a[200001];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int n; long long m;
	cin >> n >> m;
	int t;
	int MIN = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> t;
		MIN = min(t, MIN);
		a[t]++;
	}
	int count = 0;
	long long sum = 0;
	for (int i = 199999; i > -1; i--) {
		if (a[i + 1]) {
			sum += a[i + 1];
			if (sum > m) {
				sum = a[i+1];
				count++;
			}
			a[i] += a[i + 1];
			a[i + 1] = 0;
		}
		if (MIN - 1 == i) {
			if (a[i + 1])count++;
			break;
		}
	}
	cout << count;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll com[200005], sum;

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n, greater<int>());
    a[n] = a[n - 1];
    ll cur = 0;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        cur += (a[i] - a[i + 1]) * 1LL * (i + 1);
        //cout << i << " " << cur << endl;
        if (cur <= k) continue;
        if ((a[i] - a[i + 1]) * 1LL * (i + 1) > k) {
            ++res;
            cur -= (a[i] - a[i + 1]) * 1LL * (i + 1);
            a[i] -= k / (i + 1);
            --i;
            continue;
        }
        cur -= (a[i] - a[i + 1]) * 1LL * (i + 1);
        ++res;
    }
    if (cur) ++res;
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll com[200005], sum;

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n, greater<int>());
    a[n] = a[n - 1];
    ll cur = 0;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        cur += (a[i] - a[i + 1]) * 1LL * (i + 1);
        //cout << i << " " << cur << endl;
        if (cur <= k) continue;
        if ((a[i] - a[i + 1]) * 1LL * (i + 1) > k) {
            ++res;
            cur -= (a[i] - a[i + 1]) * 1LL * (i + 1);
            a[i] -= k / (i + 1);
            --i;
            continue;
        }
        cur = 0;
        --i;
        ++res;
    }
    if (cur) ++res;
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll hi[200005];

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        hi[0]++;
        hi[a[i] + 1]--;
    }
    for (int i = 1; i < 200005; ++i)
        hi[i] += hi[i - 1];
    int cur = 0, res = 0;
    for (int i = 200000; hi[i] != hi[0]; --i) {
        if (cur + hi[i] <= k) {
            cur += hi[i];
            continue;
        }
        cur = hi[i];
        ++res;
    }
    if (cur) ++res;
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll hi[200005];

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        hi[0]++;
        hi[a[i] + 1]--;
    }
    for (int i = 1; i < 200005; ++i)
        hi[i] += hi[i - 1];
    int cur = 0, res = 0;
    for (int i = 200001; hi[i] != hi[0]; --i) {
        if (cur + hi[i - 1] <= k) {
            cur += hi[i - 1];
            continue;
        }
        cur = 0;
        ++res;
    }
    if (cur) ++res;
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll hi[200005];

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        hi[0]++;
        hi[a[i] + 1]--;
    }
    for (int i = 1; i < 200005; ++i)
        hi[i] += hi[i - 1];
    int cur = 0, res = 0;
    for (int i = 200000; i > 0; --i) {
        if (cur + hi[i] <= k) {
            cur += hi[i];
            continue;
        }
        cur = hi[i];
        ++res;
    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll hi[200005];

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        hi[0]++;
        hi[a[i] + 1]--;
    }
    for (int i = 1; i < 200005; ++i)
        hi[i] += hi[i - 1];
    int cur = 0, res = 0;
    for (int i = 200001; hi[i - 1] != hi[0]; --i) {
        if (cur + hi[i - 1] <= k) {
            cur += hi[i - 1];
            continue;
        }
        cur = 0;
        ++res;
    }
    if (cur) ++res;
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];
ll hi[200005];

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        hi[0]++;
        hi[a[i] + 1]--;
    }
    for (int i = 1; i < 200005; ++i)
        hi[i] += hi[i - 1];
    int cur = 0, res = 0;
    for (int i = 200000; hi[i] != hi[0]; --i) {
        if (cur + hi[i] <= k) {
            cur += hi[i];
            continue;
        }
        cur = hi[i];
        ++res;
    }
    ++res;
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_cxx;

typedef double db;
typedef long long ll;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;

#define F          first
#define S          second
#define pnl        printf("\n")
#define sz(x)      (int)x.size()
#define sf(x)      scanf("%d",&x)
#define pf(x)      printf("%d\n",x)
#define all(x)     x.begin(),x.end()
#define rall(x)    x.rbegin(),x.rend()
#define rep(i, n)  for(int i = 0; i < n; ++i)

const db eps = 1e-9;
const db pi = acos(-1);
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1000 * 1000 * 1000 + 7;

int n, k, a[200005];

int main() {
    scanf("%d%d", &n, &k);
    if (n == 1) return !printf("%d\n", 0);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n, greater<int>());
    ll cur = 0;
    int res = 0;
    int j = 0;
    while (j < n - 1) {
        if (j + 1 < n && cur + (a[j] - a[j + 1]) * 1LL * (j + 1) <= k) {
            cur += (a[j] - a[j + 1]) * 1LL * (j + 1);
            ++j;
            continue;
        }
        ++res;
        if (cur == 0) a[j] -= k / (j + 1);
        cur = 0;
    }
    if (cur) ++res;
    cout << res << endl;
    // ll need = 0;
    // for (int i = 0; i < n; ++i)
    //     need += a[i] - a[n - 1];
    // need = (need + k - 1) / k;
    // cout << need << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=400005;
int num[N],a[N],f[N],l[N],n,m,r[N],ans[N];
int cmp(int x,int y)
{
	return l[x]<l[y];
}
int find(int x)
{
	int ans=0;
	for (;x;x-=x&-x)ans+=num[x];
	return ans;
}
void insert(int x,int y)
{
	for (;x<=n;x+=x&-x)num[x]+=y;
}
signed main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)l[i]=n+1,r[i]=0;
	for (int i=1;i<=n;i++)
	 scanf("%d",&a[i]),l[a[i]]=min(l[a[i]],i),r[a[i]]=max(r[a[i]],i);
	for (int i=1;i<=m;i++)f[i]=i;
	sort(f+1,f+m+1,cmp);
	for (int i=2;i<=m;i++)
	 if (l[f[i]]<=r[f[i-1]]&&l[f[i]]!=n+1&&r[f[i-1]]!=0)
	  {
	  	puts("NO");
	  	return 0;
	  }
	for (int i=m;i;i--)
	 if (l[i]!=n+1)
	  {
		insert(l[i],i);
		insert(r[i]+1,-i);
	  }
	for (int i=1;i<=n;i++)ans[i]=find(i);
	for (int i=1;i<n;i++)
	 if (ans[i]!=0&&ans[i+1]==0)ans[i+1]=ans[i];
	for (int i=n;i>1;i--)
	 if (ans[i]!=0&&ans[i-1]==0)ans[i-1]=ans[i];
	puts("YES");
	for (int i=1;i<=n;i++)
	 if (ans[i]==0)printf("%d ",n);
	 else printf("%lld ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=400005;
int num[N],a[N],f[N],l[N],n,m,r[N],ans[N];
struct Tree
{
	int num,l,r,flag;
}T[N*4];
int cmp(int x,int y)
{
	return l[x]<l[y];
}
void down(int x)
{
	if (T[x].flag)
	 {
	 	T[x*2].flag=T[x*2].num=T[x*2+1].num=T[x*2+1].flag=T[x].flag;
	 	T[x].flag=0;
	 }
}
void build(int x,int l,int r)
{
	T[x].l=l;T[x].r=r;
	if (l==r)
	 {
	 	T[x].num=a[l];
	 	return;
	 }
	int mid=(l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
	T[x].num=max(T[x*2].num,T[x*2+1].num);
}
void change(int x,int l,int r,int s)
{
	if (T[x].l>r||T[x].r<l)return;
	down(x);
	if (T[x].l>=l&&T[x].r<=r)
	 {
	 	T[x].num=T[x].flag=s;
	 	return;
	 }
	change(x*2,l,r,s);
	change(x*2+1,l,r,s);
	T[x].num=max(T[x*2].num,T[x*2+1].num);
}
int find(int x,int l,int r)
{
	if (T[x].l>r||T[x].r<l)return 0;
	down(x);
	if (T[x].l>=l&&T[x].r<=r)return T[x].num;
	return max(find(x*2,l,r),find(x*2+1,l,r));
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=m;i++)l[i]=n+1,r[i]=0;
	for (int i=1;i<=n;i++)
	 scanf("%lld",&a[i]),l[a[i]]=min(l[a[i]],i),r[a[i]]=max(r[a[i]],i);
	if (l[m]==n+1)
	 {
	 	for (int i=1;i<=n;i++)
	 	 if (a[i]==0)
	 	  {
	 	  	l[m]=r[m]=i;
	 	  	a[i]=m;
	 	  	break;
		  }
		if (l[m]==n+1)
		 {
		 	puts("NO");
		 	return 0;
		 }
	 }
	if (l[m]==n+1&&l[0]!=n+1)
	 {
	 	puts("NO");
	 	return 0;
	  }
	build(1,1,n);
	for (int i=1;i<=m;i++)
	 if (l[i]!=n+1)change(1,l[i],r[i],i);
	for (int i=1;i<=n;i++)ans[i]=find(1,i,i);
	for (int i=1;i<=n;i++)
	 if (ans[i]!=a[i]&&a[i]!=0)
	  {
	  	puts("NO");
	  	return 0;
	  }
	for (int i=1;i<n;i++)
	 if (ans[i]!=0&&ans[i+1]==0)ans[i+1]=ans[i];
	for (int i=n;i>1;i--)
	 if (ans[i]!=0&&ans[i-1]==0)ans[i-1]=ans[i];
	puts("YES");
	for (int i=1;i<=n;i++)
	 if (ans[i]==0)printf("%lld ",m);
	 else printf("%lld ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=400005;
int num[N],a[N],f[N],l[N],n,m,r[N],ans[N];
struct Tree
{
	int num,l,r,flag;
}T[N*4];
int cmp(int x,int y)
{
	return l[x]<l[y];
}
void down(int x)
{
	if (T[x].flag)
	 {
	 	T[x*2].flag=T[x*2].num=T[x*2+1].num=T[x*2+1].flag=T[x].flag;
	 	T[x].flag=0;
	 }
}
void build(int x,int l,int r)
{
	T[x].l=l;T[x].r=r;
	if (l==r)
	 {
	 	T[x].num=a[l];
	 	return;
	 }
	int mid=(l+r)/2;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
	T[x].num=max(T[x*2].num,T[x*2+1].num);
}
void change(int x,int l,int r,int s)
{
	if (T[x].l>r||T[x].r<l)return;
	down(x);
	if (T[x].l>=l&&T[x].r<=r)
	 {
	 	T[x].num=T[x].flag=s;
	 	return;
	 }
	change(x*2,l,r,s);
	change(x*2+1,l,r,s);
	T[x].num=max(T[x*2].num,T[x*2+1].num);
}
int find(int x,int l,int r)
{
	if (T[x].l>r||T[x].r<l)return 0;
	down(x);
	if (T[x].l>=l&&T[x].r<=r)return T[x].num;
	return max(find(x*2,l,r),find(x*2+1,l,r));
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=m;i++)l[i]=n+1,r[i]=0;
	for (int i=1;i<=n;i++)
	 scanf("%lld",&a[i]),l[a[i]]=min(l[a[i]],i),r[a[i]]=max(r[a[i]],i);
	build(1,1,n);
	for (int i=1;i<=m;i++)
	 if (l[i]!=n+1)change(1,l[i],r[i],i);
	for (int i=1;i<=n;i++)ans[i]=find(1,i,i);
	for (int i=1;i<=n;i++)
	 if (ans[i]!=a[i])
	  {
	  	puts("NO");
	  	return 0;
	  }
	for (int i=1;i<n;i++)
	 if (ans[i]!=0&&ans[i+1]==0)ans[i+1]=ans[i];
	for (int i=n;i>1;i--)
	 if (ans[i]!=0&&ans[i-1]==0)ans[i-1]=ans[i];
	puts("YES");
	for (int i=1;i<=n;i++)
	 if (ans[i]==0)printf("%lld ",m);
	 else printf("%lld ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=400005;
int num[N],a[N],f[N],l[N],n,m,r[N],ans[N];
int cmp(int x,int y)
{
	return l[x]<l[y];
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	for (int i=1;i<=m;i++)l[i]=n+1,r[i]=0;
	for (int i=1;i<=n;i++)
	 scanf("%lld",&a[i]),l[a[i]]=min(l[a[i]],i),r[a[i]]=max(r[a[i]],i);
	for (int i=m;i;i--)
	 if (l[i]!=n+1)
	  for (int j=l[i];j<=r[i];j++)
	   {
	   	if (ans[j])
	   	 {
	   	 	puts("NO");
	   	 	return 0;
		 }
		ans[j]=i;
	   }
	for (int i=1;i<n;i++)
	 if (ans[i]!=0&&ans[i+1]==0)ans[i+1]=ans[i];
	for (int i=n;i>1;i--)
	 if (ans[i]!=0&&ans[i-1]==0)ans[i-1]=ans[i];
	puts("YES");
	for (int i=1;i<=n;i++)
	 if (ans[i]==0)printf("%lld ",m);
	 else printf("%lld ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=400005;
int num[N],a[N],f[N],l[N],n,m,r[N],ans[N];
int cmp(int x,int y)
{
	return l[x]<l[y];
}
int find(int x)
{
	int ans=0;
	for (;x;x-=x&-x)ans+=num[x];
	return ans;
}
void insert(int x,int y)
{
	for (;x<=n;x+=x&-x)num[x]+=y;
}
signed main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)l[i]=n+1,r[i]=0;
	for (int i=1;i<=n;i++)
	 scanf("%d",&a[i]),l[a[i]]=min(l[a[i]],i),r[a[i]]=max(r[a[i]],i);
	for (int i=1;i<=m;i++)f[i]=i;
	sort(f+1,f+m+1,cmp);
	for (int i=2;i<=m;i++)
	 if (l[f[i]]<=r[f[i-1]]&&l[f[i]]!=n+1&&r[f[i-1]]!=0)
	  {
	  	puts("NO");
	  	return 0;
	  }
	for (int i=m;i;i--)
	 if (l[i]!=n+1)
	  {
		insert(l[i],i);
		insert(r[i]+1,-i);
	  }
	for (int i=1;i<=n;i++)ans[i]=find(i);
	for (int i=1;i<n;i++)
	 if (ans[i]!=0&&ans[i+1]==0)ans[i+1]=ans[i];
	for (int i=n;i>1;i--)
	 if (ans[i]!=0&&ans[i-1]==0)ans[i-1]=ans[i];
	puts("YES");
	for (int i=1;i<=n;i++)
	 if (ans[i]==0)printf("1 ");
	 else printf("%lld ",ans[i]);
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>

using namespace std;

struct node{
	int left,right;
	int lazy,num;
}t[1000005];

int n,q;
int a[200005],mina[200005],maxa[200005],b[200005];

void buildtree(int id,int l,int r){
	t[id].left=l,t[id].right=r;
	t[id].lazy=0;
	if(l==r){
		t[id].num=a[l];
		return;
	}
	int mid=(l+r)/2;
	buildtree(id<<1,l,mid);
	buildtree(id<<1|1,mid+1,r);
}

void change(int id,int l,int r,int c){
	if(t[id].left==l&&t[id].right==r){
		t[id].lazy=c;
		return;
	}
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(t[id<<1].right>=r)
		change(id<<1,l,r,c);
	else if(t[id<<1|1].left<=l)
		change(id<<1|1,l,r,c);
	else{
		change(id<<1,l,t[id<<1].right,c);
		change(id<<1|1,t[id<<1|1].left,r,c);
	}
}

int query(int id,int p){
	if(t[id].left==p&&t[id].right==p)
		return t[id].lazy?t[id].lazy:t[id].num;
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(p<=t[id<<1].right)
		return query(id<<1,p);
	else
		return query(id<<1|1,p);
}

int main(){
	cin>>n>>q;
	for(int i=1;i<=q;i++)
		mina[i]=1<<30,maxa[i]=-1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mina[a[i]]=min(mina[a[i]],i),maxa[a[i]]=max(maxa[a[i]],i);
	}
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(a[i]!=0)
			flag=false;
	if(flag){
		cout<<"YES"<<endl;
		for(int i=1;i<=n;i++)
			cout<<q<<' ';
		cout<<endl;
		return 0;
	}
	buildtree(1,1,n);
	for(int i=1;i<=q;i++)
		if(mina[i]!=1<<30)
			change(1,mina[i],maxa[i],i);
	for(int i=1;i<=n;i++)
		b[i]=query(1,i);
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i]&&a[i]!=0)
			flag=true;
	if(flag){
		cout<<"NO"<<endl;
		return 0;
	}
	int tmp=q;
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			if(mina[q]==1<<30)
				b[i]=q;
			flag=true;
			break;
		}
	}
	if(!flag&&mina[q]==1<<30){
		cout<<"NO"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==0){
			if(i==1||b[i-1]==0)
				continue;
			b[i]=b[i-1];
		}
	}
	for(int i=n;i>=1;i--){
		if(b[i]==0){
			if(i==n||b[i+1]==0)
				continue;
			b[i]=b[i+1];
		}
	}
	cout<<"YES"<<endl;
	for(int i=1;i<=n;i++)
		cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

struct node{
	int left,right;
	int lazy,num;
}t[1000005];

int n,q;
int a[200005],mina[200005],maxa[200005],b[200005];

void buildtree(int id,int l,int r){
	t[id].left=l,t[id].right=r;
	t[id].lazy=0;
	if(l==r){
		t[id].num=a[l];
		return;
	}
	int mid=(l+r)/2;
	buildtree(id<<1,l,mid);
	buildtree(id<<1|1,mid+1,r);
}

void change(int id,int l,int r,int c){
	if(t[id].left==l&&t[id].right==r){
		t[id].lazy=c;
		return;
	}
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(t[id<<1].right>=r)
		change(id<<1,l,r,c);
	else if(t[id<<1|1].left<=l)
		change(id<<1|1,l,r,c);
	else{
		change(id<<1,l,t[id<<1].right,c);
		change(id<<1|1,t[id<<1|1].left,r,c);
	}
}

int query(int id,int p){
	if(t[id].left==p&&t[id].right==p)
		return t[id].lazy?t[id].lazy:t[id].num;
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(p<=t[id<<1].right)
		return query(id<<1,p);
	else
		return query(id<<1|1,p);
}

int main(){
	cin>>n>>q;
	for(int i=1;i<=q;i++)
		mina[i]=1<<30,maxa[i]=-1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mina[a[i]]=min(mina[a[i]],i),maxa[a[i]]=max(maxa[a[i]],i);
	}
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(a[i]!=0)
			flag=false;
	if(flag){
		cout<<"YES"<<endl;
		for(int i=1;i<=n;i++)
			cout<<q<<' ';
		cout<<endl;
		return 0;
	}
	buildtree(1,1,n);
	for(int i=1;i<=q;i++)
		if(mina[i]!=1<<30)
			change(1,mina[i],maxa[i],i);
	for(int i=1;i<=n;i++)
		b[i]=query(1,i);
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i]&&a[i]!=0)
			flag=true;
	if(flag){
		cout<<"NO"<<endl;
		return 0;
	}
	int tmp=q;
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			if(mina[q]==1<<30)
				b[i]=q;
			flag=true;
			break;
		}
	}
	if(!flag&&mina[q]==1<<30){
		cout<<"NO"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==0){
			if(i==1||b[i-1]==0)
				continue;
			b[i]=b[i-1];
		}
	}
	for(int i=n;i>=1;i--){
		if(b[i]==0){
			if(i==n||b[i+1]==0)
				continue;
			b[i]=b[i+1];
		}
	}
	cout<<"YES"<<endl;
	for(int i=1;i<=n;i++)
		cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

struct node{
	int left,right;
	int lazy,num;
}t[1000005];

int n,q;
int a[200005],mina[200005],maxa[200005],b[200005];

void buildtree(int id,int l,int r){
	t[id].left=l,t[id].right=r;
	t[id].lazy=0;
	if(l==r){
		t[id].num=a[l];
		return;
	}
	int mid=(l+r)/2;
	buildtree(id<<1,l,mid);
	buildtree(id<<1|1,mid+1,r);
}

void change(int id,int l,int r,int c){
	if(t[id].left==l&&t[id].right==r){
		t[id].lazy=c;
		return;
	}
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(t[id<<1].right>=r)
		change(id<<1,l,r,c);
	else if(t[id<<1|1].left<=l)
		change(id<<1|1,l,r,c);
	else{
		change(id<<1,l,t[id<<1].right,c);
		change(id<<1|1,t[id<<1|1].left,r,c);
	}
}

int query(int id,int p){
	if(t[id].left==p&&t[id].right==p)
		return t[id].lazy?t[id].lazy:t[id].num;
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(p<=t[id<<1].right)
		return query(id<<1,p);
	else
		return query(id<<1|1,p);
}

int main(){
	cin>>n>>q;
	for(int i=1;i<=q;i++)
		mina[i]=1<<30,maxa[i]=-1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mina[a[i]]=min(mina[a[i]],i),maxa[a[i]]=max(maxa[a[i]],i);
	}
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(a[i]!=0)
			flag=false;
	if(flag){
		cout<<"YES"<<endl;
		for(int i=1;i<=n;i++)
			cout<<q<<' ';
		cout<<endl;
		return 0;
	}
	buildtree(1,1,n);
	for(int i=1;i<=q;i++)
		if(mina[i]!=1<<30)
			change(1,mina[i],maxa[i],i);
	for(int i=1;i<=n;i++)
		b[i]=query(1,i);
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i]&&a[i]!=0)
			flag=true;
	if(flag){
		cout<<"NO"<<endl;
		return 0;
	}
	int tmp=q;
	for(int i=1;i<=n;i++){
		if(b[i]==0){
			while(mina[tmp]!=1<<30&&tmp>=1)
				tmp--;
			if(tmp<1)
				break;
			mina[tmp]=i;
			b[i]=tmp;
		}
	}
	if(mina[q]==1<<30){
		cout<<"NO"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==0){
			if(i==1||b[i-1]==0)
				continue;
			b[i]=b[i-1];
		}
	}
	for(int i=n;i>=1;i--){
		if(b[i]==0){
			if(i==n||b[i+1]==0)
				continue;
			b[i]=b[i+1];
		}
	}
	cout<<"YES"<<endl;
	for(int i=1;i<=n;i++)
		cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

struct node{
	int left,right;
	int lazy,num;
}t[1000005];

int n,q;
int a[200005],mina[200005],maxa[200005],b[200005];

void buildtree(int id,int l,int r){
	t[id].left=l,t[id].right=r;
	t[id].lazy=0;
	if(l==r){
		t[id].num=a[l];
		return;
	}
	int mid=(l+r)/2;
	buildtree(id<<1,l,mid);
	buildtree(id<<1|1,mid+1,r);
}

void change(int id,int l,int r,int c){
	if(t[id].left==l&&t[id].right==r){
		t[id].lazy=c;
		return;
	}
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(t[id<<1].right>=r)
		change(id<<1,l,r,c);
	else if(t[id<<1|1].left<=l)
		change(id<<1|1,l,r,c);
	else{
		change(id<<1,l,t[id<<1].right,c);
		change(id<<1|1,t[id<<1|1].left,r,c);
	}
}

int query(int id,int p){
	if(t[id].left==p&&t[id].right==p)
		return t[id].lazy?t[id].lazy:t[id].num;
	if(t[id].lazy){
		t[id<<1].lazy=t[id<<1|1].lazy=t[id].lazy;
		t[id].lazy=0;
	}
	if(p<=t[id<<1].right)
		return query(id<<1,p);
	else
		return query(id<<1|1,p);
}

int main(){
	cin>>n>>q;
	for(int i=1;i<=q;i++)
		mina[i]=1<<30,maxa[i]=-1;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		mina[a[i]]=min(mina[a[i]],i),maxa[a[i]]=max(maxa[a[i]],i);
	}
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(a[i]!=0)
			flag=false;
	if(flag){
		cout<<"YES"<<endl;
		for(int i=1;i<=n;i++)
			cout<<1<<' ';
		cout<<endl;
		return 0;
	}
	buildtree(1,1,n);
	for(int i=1;i<=q;i++)
		if(mina[i]!=1<<30)
			change(1,mina[i],maxa[i],i);
	for(int i=1;i<=n;i++)
		b[i]=query(1,i);
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i]&&a[i]!=0)
			flag=true;
	if(flag){
		cout<<"NO"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==0){
			if(i==1||b[i-1]==0)
				continue;
			b[i]=b[i-1];
		}
	}
	for(int i=n;i>=1;i--){
		if(b[i]==0){
			if(i==n||b[i+1]==0)
				continue;
			b[i]=b[i+1];
		}
	}
	cout<<"YES"<<endl;
	for(int i=1;i<=n;i++)
		cout<<b[i]<<' ';
	cout<<endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=2e5+7;
int a[N],l[N],r[N],b[N],fa[N];
int n,m,p,p1;
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]) p=1;
		if (a[i]==m) p1=1;
	}
	if (!p) {
		puts("YES");
		for (int i=1;i<n;i++)
			printf("1 ");
		printf("%d\n",m);
		return 0;
	}
	if (!p1) {
		for (int i=1;i<=n;i++)
			if (!a[i]) {
				a[i]=m,p1=1;
				break;
			}
		if (!p1) return puts("NO"),0;
	}
	for (int i=1;i<=n;i++) {
		if (!a[i]) continue;
		for (int j=i-1;j && !a[j];j--) a[j]=a[i];
		for (int j=i+1;j<=n && !a[j];j++) a[j]=a[i];
	}
	memset(l,60,sizeof l);
	for (int i=1;i<=n;i++) {
		l[a[i]]=min(l[a[i]],i);
		r[a[i]]=max(r[a[i]],i);
	}
	for (int i=1;i<=n+2;i++) fa[i]=i;
	for (int i=m;i>=1;i--) {
		if (r[i]==0) continue;
		for (int j=l[i];j<=r[i];) {
			int t=find(j);
			if (t==j) {
				b[j]=i;fa[j]=j+1;
			}
			j=t;
		}
	}
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) return puts("NO"),0;
	puts("YES");
	for (int i=1;i<=n;i++)
		printf("%d ",a[i]);
}


#include <cstdio>
using namespace std;
const int N=2e5+7;
int a[N],vis[N];
int n,m,p,p1;
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]) p=1;
		if (a[i]==m) p1=1;
	}
	if (!p) {
		puts("YES");
		for (int i=1;i<n;i++)
			printf("1 ");
		printf("%d\n",m);
		return 0;
	}
	if (!p1) {
		if (a[1]==0) a[1]=m;
		else if (a[n]==0) a[n]=m;
		else {
			for (int i=1,la=0;i<=n;i++) {
				if (a[i] && la && a[i]!=la && a[i-1]==0) {
					a[i-1]=m;
					p1=1;
					break;
				}
				if (a[i]) la=a[i];
			}
			if (!p1) return puts("NO");
		}
	}
	for (int i=1;i<=n;i++) {
		if (!a[i]) continue;
		for (int j=i-1;j && !a[j];j--) a[j]=a[i];
		for (int j=i+1;j<=n && !a[j];j++) a[j]=a[i];
	}
	for (int i=1;i<=n;i++) {
		if (a[i+1]!=a[i]) {
			if (vis[a[i]]) return puts("NO"),0;
			vis[a[i]]=1;
		}
	}
	puts("YES");
	for (int i=1;i<=n;i++)
		printf("%d ",a[i]);
}


#include <cstdio>
using namespace std;
const int N=2e5+7;
int a[N],vis[N];
int n,m,p;
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]) p=1;
	}
	if (!p) {
		puts("YES");
		for (int i=1;i<=n;i++)
			printf("1 ");
		return 0;
	}
	for (int i=1;i<=n;i++) {
		if (!a[i]) continue;
		for (int j=i-1;j && !a[j];j--) a[j]=a[i];
		for (int j=i+1;j<=n && !a[j];j++) a[j]=a[i];
	}
	for (int i=1;i<=n;i++) {
		if (a[i+1]!=a[i]) {
			if (vis[a[i]]) return puts("NO"),0;
			vis[a[i]]=1;
		}
	}
	puts("YES");
	for (int i=1;i<=n;i++)
		printf("%d ",a[i]);
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=2e5+7;
int a[N],l[N],r[N],b[N],fa[N];
int n,m,p,p1;
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]) p=1;
		if (a[i]==m) p1=1;
	}
	if (!p) {
		puts("YES");
		for (int i=1;i<n;i++)
			printf("1 ");
		printf("%d\n",m);
		return 0;
	}
	if (!p1) {
		if (a[1]==0) a[1]=m;
		else if (a[n]==0) a[n]=m;
		else {
			for (int i=1,la=0;i<=n;i++) {
				if (a[i] && la && a[i]!=la && a[i-1]==0) {
					a[i-1]=m;
					p1=1;
					break;
				}
				if (a[i]) la=a[i];
			}
			if (!p1) return puts("NO");
		}
	}
	for (int i=1;i<=n;i++) {
		if (!a[i]) continue;
		for (int j=i-1;j && !a[j];j--) a[j]=a[i];
		for (int j=i+1;j<=n && !a[j];j++) a[j]=a[i];
	}
	memset(l,60,sizeof l);
	for (int i=1;i<=n;i++) {
		l[a[i]]=min(l[a[i]],i);
		r[a[i]]=max(r[a[i]],i);
	}
	for (int i=1;i<=n;i++) fa[i]=i;
	for (int i=m;i>=1;i--) {
		if (r[i]==0) continue;
		for (int j=r[i];j>=l[i];j--) {
			if (fa[j]!=j) j=find(j);
			fa[j]=j-1;b[j]=i;
		}
	}
	for (int i=1;i<=n;i++) if (a[i]!=b[i]) return puts("NO"),0;
	puts("YES");
	for (int i=1;i<=n;i++)
		printf("%d ",a[i]);
}


#include<bits/stdc++.h>
using namespace std;
int n,q;
int a[200005],tt[800005],vis[200005],l[200005],ans[200005];
void up(int rt)
{
	tt[rt]=min(tt[rt<<1],tt[rt<<1|1]);
	return;
}
void bt(int rt,int ll,int rr)
{
	if(ll==rr)
	{
		if(a[ll]) tt[rt]=a[ll];
		else tt[rt]=q;
		return;
	}
	int mid=(ll+rr)>>1;
	bt(rt<<1,ll,mid);
	bt(rt<<1|1,mid+1,rr);
	up(rt);
	return;
}
int query(int rt,int ll,int rr,int L,int R)
{
	if(ll==L&&rr==R) return tt[rt];
	int mid=(ll+rr)>>1;
	if(R<=mid) return query(rt<<1,ll,mid,L,R);
	else if(L>mid) return query(rt<<1|1,mid+1,rr,L,R);
	else return min(query(rt<<1,ll,mid,L,mid),query(rt<<1,ll,mid,mid+1,R));
}
int main()
{
	scanf("%d%d",&n,&q);
	int mn=q;
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		if(a[i]) mn=min(mn,a[i]);
		if(!vis[a[i]]) l[a[i]]=i;
		vis[a[i]]=i;
	}
	bt(1,1,n);
	ans[1]=mn;
	int qq=mn;
	for(int i=1;i<=q;++i)
	{
		int mx=0;
		if(vis[i])
		{
			mx=query(1,1,n,l[i],vis[i]);
			if(mx<i) {puts("NO");return 0;}
			ans[l[i]]+=i-qq;
			ans[vis[i]+1]+=qq-i;
			qq=i;
		}
	}
	for(int i=1;i<=n;++i) ans[i]=ans[i-1]+ans[i];
	if(!vis[q])
	{
		int ff=1;
		for(int i=1;i<=n;++i) if(a[i]==0) {ff=0;ans[i]=q;break;}
		if(ff)
		{
			puts("NO");return 0;
		}
	}
	puts("YES");
	for(int i=1;i<=n;++i) printf("%d ",ans[i]);
	return 0;
}