#include<bits/stdc++.h>
#define int long long
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
uniform_int_distribution<int> uid(l, r);
return uid(rng);
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt=1;
//cout<<(1LL<<31LL)<<endl;
//cin>>tt;
//int T=
while(tt--)
{
int n,m;
cin>>n>>m;
int mx=0,sum=0;
int arr[n];
map<int,int>mp;
for(int i=0;i<n;i++){
int x;
cin>>arr[i];
mp[arr[i]]++;
sum+=arr[i];
}
if(sum%2==0){
if(n==m)
cout<<m<<"\n";
else if(m<n){
if((n-m)%2==0)
cout<<2<<"\n";
else cout<<1<<"\n";
}
else cout<<abs(m-n)<<"\n";
}
else
cout<<0<<"\n";
}}
/*stolen stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Copy