#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main() {
  string s; cin >> s;

  int cnt = 0;
  for (int i = 0; i < s.size(); ++i) {
    string str = s.substr(i, 4);
    if (str == "ZONe") cnt ++;
  }

  cout << cnt << endl;

  return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define REPA(i,j) for(int i=1;i<=j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int INF=1<<30;
inline void read(int &x){
//	short neg=1;
	x=0;
	char c=getchar();
	/*while(c<'0'||c>'9'){
		if(c=='-')neg=-1;
		c=getchar();
	}*/
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+(c^48),c=getchar();
	}
//	x*=neg;
}
const int N=3e5+10;
int n,k;
int a[N];
int cnt[N];
pii minn[N];// without itself
int main(void){
	read(n);read(k);
	REP(i,n)read(a[i]);
	memset(cnt,0,sizeof(cnt));
	REP(i,n)cnt[a[i]]++;
	minn[1]=mp(cnt[0],0);
	for(int i=2;i<n;i++){
		if(cnt[i-1]<minn[i-1].fi){
			minn[i]=mp(cnt[i-1],i-1);
		}
		else{
			minn[i]=minn[i-1];
		}
	}
	ll ans=0;
	int m=0,it=0;//cnt[it]==0
	while(cnt[it]!=0)it++;//find the first i->0
	while(k>0&&cnt[0]-m>0&&it>0){
//		cout<<it<<' '<<m<<' '<<ans<<' '<<minn[it].fi<<endl;
		ans+=it*(min(k,minn[it].fi-m));
		k-=minn[it].fi-m;
		m=minn[it].fi;
		it=minn[it].se;
	}
	printf("%lld",ans);
	return 0;
}
