#include <bits/stdc++.h>
#define               ll long long int
#define               usll unsigned long long int
#define               F first
#define               S second
#define               _R return ;
#define               R return 0;
#define               pb push_back
#define               endln "\n"
#define               MAXX 200007
#define               MX 3002
#define               MOD 111539786
#define               PI 3,1415926535897
#define               sps setprecision
#define               leng(s) s.size()-1
#define               lengall(s) s.size()
#define               F0R(i , x , j , n) for(ll i = x ; i >= n ; i -= j)
#define               FOR(i , x , j , n) for(ll i = x ; i <= n ; i += j)
#define               REN(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define               ALL_OF_ME  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define               debug(a) cout << (#a) << " = " << a << "\n";
#define               see(a) cout<< a << "\n";
#define               line(a) cout << a <<" ";
#define               newline cout<< "\n";
#define               space(a,b) cout << a << " " << b << "\n";
#define               goodluck_code() int main()
#define  I_too_stupid_to_solve_a_problem_BUT_I_not_too_stupid_to_realize_who_I_love return 0;
using namespace std;

template <class Object>
Object Reverse(Object obj , ll l , ll r){
	while(l < r) swap(obj[l] , obj[r]), l++ , r--;
}

template <class Object>
Object Swap(Object a , Object b){
	Object tmp = a;
			a = b;
			b = tmp;
}

template <class Object>
Object Ceil(Object a , Object b){
	if(a % b == 0){
		return a / b;
	}else{
		return a / b + 1;
	}
}

template <class Object>
Object Gcd(Object a , Object b){
	if(b == 0){
		return a;
	}else{
		return Gcd(b , a % b);
	}
}

template <class Object>
Object Loop(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		line(obj[i])
	}
	return obj;
}

template <class Object>
Object Looppair(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		space(obj[i].F , obj[i].S)
	}
	return obj;
}

bool zoe(const pair<ll , ll>& i ,const pair<ll , ll>& j){
	return (i.S > j.S);
}

class Start{

	public :

		ll n , k;
		ll a[MAXX];

		void LOOPER(){
			cin >> n >> k;

			FOR(i ,1 , 1 , n) cin >> a[i];

			slove(a , n , k);

		}

	private :

		void slove(ll a[] , ll n , ll k){

			ll solan = Ceil(n , 2ll);

			ll sum = 0;

			vector<pair<ll , ll> > ve;

			map<ll , ll> mp;

			map<ll , ll> :: iterator it;

			FOR(i , 1 , 1 , n) mp[a[i]]++;

			REN(it , mp){
				ve.pb(make_pair(it->F , it->S));
				sum += Ceil(it->S , 2ll);
			}

			if(k < n){
				if(sum == solan) see(n)
				else see(n - 1);
				return ;
			}

			sort(ve.begin() , ve.end() , zoe);

			FOR(i , 0 , 1 , leng(ve)){
				if(solan == 0) break;
				if(solan < Ceil(ve[i].S , 2ll)){
					solan -= solan;
					sum += Ceil(ve[i].S , 2ll);
				}else{
					solan -= Ceil(ve[i].S , 2ll);
					sum += ve[i].S;
				}
			}

			see(sum)

		}

};
Start huy;
void _love(){
	huy.LOOPER();
}
void _nang_am(){
/*
The idea bad is yours

					Or

					The idea good is your

								  		And more importantly

															this code is yours
*/
}
goodluck_code(){
  _love();
  _nang_am();
  R
}


#include <bits/stdc++.h>
#define               ll long long int
#define               usll unsigned long long int
#define               F first
#define               S second
#define               _R return ;
#define               R return 0;
#define               pb push_back
#define               endln "\n"
#define               MAXX 200007
#define               MX 3002
#define               MOD 111539786
#define               PI 3,1415926535897
#define               sps setprecision
#define               leng(s) s.size()-1
#define               lengall(s) s.size()
#define               F0R(i , x , j , n) for(ll i = x ; i >= n ; i -= j)
#define               FOR(i , x , j , n) for(ll i = x ; i <= n ; i += j)
#define               REN(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define               ALL_OF_ME  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define               debug(a) cout << (#a) << " = " << a << "\n";
#define               see(a) cout<< a << "\n";
#define               line(a) cout << a <<" ";
#define               newline cout<< "\n";
#define               space(a,b) cout << a << " " << b << "\n";
#define               goodluck_code() int main()
#define  I_too_stupid_to_solve_a_problem_BUT_I_not_too_stupid_to_realize_who_I_love return 0;
using namespace std;

template <class Object>
Object Reverse(Object obj , ll l , ll r){
	while(l < r) swap(obj[l] , obj[r]), l++ , r--;
}

template <class Object>
Object Swap(Object a , Object b){
	Object tmp = a;
			a = b;
			b = tmp;
}

template <class Object>
Object Ceil(Object a , Object b){
	if(a % b == 0){
		return a / b;
	}else{
		return a / b + 1;
	}
}

template <class Object>
Object Gcd(Object a , Object b){
	if(b == 0){
		return a;
	}else{
		return Gcd(b , a % b);
	}
}

template <class Object>
Object Loop(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		line(obj[i])
	}
	return obj;
}

template <class Object>
Object Looppair(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		space(obj[i].F , obj[i].S)
	}
	return obj;
}

bool zoe(const pair<ll , ll>& i ,const pair<ll , ll>& j){
	return (i.S > j.S);
}

class Start{

	public :

		ll n , k;
		ll a[MAXX];

		void LOOPER(){
			cin >> n >> k;

			FOR(i ,1 , 1 , n) cin >> a[i];

			slove(a , n , k);

		}

	private :

		void slove(ll a[] , ll n , ll k){

			ll solan = Ceil(n , 2ll);

			ll sum = 0;

			vector<pair<ll , ll> > ve;

			map<ll , ll> mp;

			map<ll , ll> :: iterator it;

			FOR(i , 1 , 1 , n) mp[a[i]]++;

			REN(it , mp){
				ve.pb(make_pair(it->F , it->S));
			}

			sort(ve.begin() , ve.end() , zoe);

			FOR(i , 0 , 1 , leng(ve)){
				if(solan == 0) break;
				if(solan < Ceil(ve[i].S , 2ll)){
					sum += solan * 2;
					solan -= solan;
				}else{
					solan -= Ceil(ve[i].S , 2ll);
					sum += ve[i].S;
				}
			}

			see(sum)

		}

};
Start huy;
void _love(){
	huy.LOOPER();
}
void _nang_am(){
/*
The idea bad is yours

					Or

					The idea good is your

								  		And more importantly

															this code is yours
*/
}
goodluck_code(){
  _love();
  _nang_am();
  R
}


#include <bits/stdc++.h>
#define               ll long long int
#define               usll unsigned long long int
#define               F first
#define               S second
#define               _R return ;
#define               R return 0;
#define               pb push_back
#define               endln "\n"
#define               MAXX 200007
#define               MX 3002
#define               MOD 111539786
#define               PI 3,1415926535897
#define               sps setprecision
#define               leng(s) s.size()-1
#define               lengall(s) s.size()
#define               F0R(i , x , j , n) for(ll i = x ; i >= n ; i -= j)
#define               FOR(i , x , j , n) for(ll i = x ; i <= n ; i += j)
#define               REN(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define               ALL_OF_ME  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define               debug(a) cout << (#a) << " = " << a << "\n";
#define               see(a) cout<< a << "\n";
#define               line(a) cout << a <<" ";
#define               newline cout<< "\n";
#define               space(a,b) cout << a << " " << b << "\n";
#define               goodluck_code() int main()
#define  I_too_stupid_to_solve_a_problem_BUT_I_not_too_stupid_to_realize_who_I_love return 0;
using namespace std;

template <class Object>
Object Reverse(Object obj , ll l , ll r){
	while(l < r) swap(obj[l] , obj[r]), l++ , r--;
}

template <class Object>
Object Swap(Object a , Object b){
	Object tmp = a;
			a = b;
			b = tmp;
}

template <class Object>
Object Ceil(Object a , Object b){
	if(a % b == 0){
		return a / b;
	}else{
		return a / b + 1;
	}
}

template <class Object>
Object Gcd(Object a , Object b){
	if(b == 0){
		return a;
	}else{
		return Gcd(b , a % b);
	}
}

template <class Object>
Object Loop(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		line(obj[i])
	}
	return obj;
}

template <class Object>
Object Looppair(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		space(obj[i].F , obj[i].S)
	}
	return obj;
}

bool zoe(const pair<ll , ll>& i ,const pair<ll , ll>& j){
	return (i.S > j.S);
}

class Start{

	public :

		ll n , k;
		ll a[MAXX];

		void LOOPER(){
			cin >> n >> k;

			FOR(i ,1 , 1 , n) cin >> a[i];

			slove(a , n , k);

		}

	private :

		void slove(ll a[] , ll n , ll k){

			ll solan = Ceil(n , 2ll);

			ll sum = 0;

			vector<pair<ll , ll> > ve;

			map<ll , ll> mp;

			map<ll , ll> :: iterator it;

			FOR(i , 1 , 1 , n) mp[a[i]]++;

			REN(it , mp){
				ve.pb(make_pair(it->F , it->S));
			}

			sort(ve.begin() , ve.end() , zoe);

			FOR(i , 0 , 1 , leng(ve)){
				if(solan == 0) break;
				if(solan < Ceil(ve[i].S , 2ll)){
					solan -= solan;
					sum += Ceil(ve[i].S , 2ll);
				}else{
					solan -= Ceil(ve[i].S , 2ll);
					sum += ve[i].S;
				}
			}

			see(sum)

		}

};
Start huy;
void _love(){
	huy.LOOPER();
}
void _nang_am(){
/*
The idea bad is yours

					Or

					The idea good is your

								  		And more importantly

															this code is yours
*/
}
goodluck_code(){
  _love();
  _nang_am();
  R
}


#include <bits/stdc++.h>
#define               ll long long int
#define               usll unsigned long long int
#define               F first
#define               S second
#define               _R return ;
#define               R return 0;
#define               pb push_back
#define               endln "\n"
#define               MAXX 200007
#define               MX 3002
#define               MOD 111539786
#define               PI 3,1415926535897
#define               sps setprecision
#define               leng(s) s.size()-1
#define               lengall(s) s.size()
#define               F0R(i , x , j , n) for(ll i = x ; i >= n ; i -= j)
#define               FOR(i , x , j , n) for(ll i = x ; i <= n ; i += j)
#define               REN(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define               ALL_OF_ME  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define               debug(a) cout << (#a) << " = " << a << "\n";
#define               see(a) cout<< a << "\n";
#define               line(a) cout << a <<" ";
#define               newline cout<< "\n";
#define               space(a,b) cout << a << " " << b << "\n";
#define               goodluck_code() int main()
#define  I_too_stupid_to_solve_a_problem_BUT_I_not_too_stupid_to_realize_who_I_love return 0;
using namespace std;

template <class Object>
Object Reverse(Object obj , ll l , ll r){
	while(l < r) swap(obj[l] , obj[r]), l++ , r--;
}

template <class Object>
Object Swap(Object a , Object b){
	Object tmp = a;
			a = b;
			b = tmp;
}

template <class Object>
Object Ceil(Object a , Object b){
	if(a % b == 0){
		return a / b;
	}else{
		return a / b + 1;
	}
}

template <class Object>
Object Gcd(Object a , Object b){
	if(b == 0){
		return a;
	}else{
		return Gcd(b , a % b);
	}
}

template <class Object>
Object Loop(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		line(obj[i])
	}
	return obj;
}

template <class Object>
Object Looppair(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		space(obj[i].F , obj[i].S)
	}
	return obj;
}

bool zoe(const pair<ll , ll>& i ,const pair<ll , ll>& j){
	return (i.S > j.S);
}

class Start{

	public :

		ll n , k;
		ll a[MAXX];

		void LOOPER(){
			cin >> n >> k;

			FOR(i ,1 , 1 , n) cin >> a[i];

			slove(a , n , k);

		}

	private :

		void slove(ll a[] , ll n , ll k){

			ll solan = Ceil(n , 2ll);

			ll sum = 0;

			vector<pair<ll , ll> > ve;

			map<ll , ll> mp;

			map<ll , ll> :: iterator it;

			FOR(i , 1 , 1 , n) mp[a[i]]++;

			REN(it , mp){
				ve.pb(make_pair(it->F , it->S));
			}

			sort(ve.begin() , ve.end() , zoe);

			FOR(i , 0 , 1 , leng(ve)){
				if(solan == 0) break;
				if(ve[i].S & 1){
					if(solan < Ceil(ve[i].S , 2ll) - 1){
						sum += solan * 2;
						solan -= solan;
					}else{
						solan -= (Ceil(ve[i].S , 2ll) - 1);
						sum += (ve[i].S - 1);
					}
				}else{
					if(solan < Ceil(ve[i].S , 2ll) ){
						sum += solan * 2;
						solan -= solan;
					}else{
						solan -= (Ceil(ve[i].S , 2ll));
						sum += ve[i].S;
					}
				}
			}

			see(sum + solan)

		}
};
Start huy;
void _love(){
	huy.LOOPER();
}
void _nang_am(){
/*
The idea bad is yours

					Or

					The idea good is your

								  		And more importantly

															this code is yours
*/
}
goodluck_code(){
  _love();
  _nang_am();
  R
}


#include <bits/stdc++.h>
#define               ll long long int
#define               usll unsigned long long int
#define               F first
#define               S second
#define               _R return ;
#define               R return 0;
#define               pb push_back
#define               endln "\n"
#define               MAXX 200007
#define               MX 3002
#define               MOD 111539786
#define               PI 3,1415926535897
#define               sps setprecision
#define               leng(s) s.size()-1
#define               lengall(s) s.size()
#define               F0R(i , x , j , n) for(ll i = x ; i >= n ; i -= j)
#define               FOR(i , x , j , n) for(ll i = x ; i <= n ; i += j)
#define               REN(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define               ALL_OF_ME  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define               debug(a) cout << (#a) << " = " << a << "\n";
#define               see(a) cout<< a << "\n";
#define               line(a) cout << a <<" ";
#define               newline cout<< "\n";
#define               space(a,b) cout << a << " " << b << "\n";
#define               goodluck_code() int main()
#define  I_too_stupid_to_solve_a_problem_BUT_I_not_too_stupid_to_realize_who_I_love return 0;
using namespace std;

template <class Object>
Object Reverse(Object obj , ll l , ll r){
	while(l < r) swap(obj[l] , obj[r]), l++ , r--;
}

template <class Object>
Object Swap(Object a , Object b){
	Object tmp = a;
			a = b;
			b = tmp;
}

template <class Object>
Object Ceil(Object a , Object b){
	if(a % b == 0){
		return a / b;
	}else{
		return a / b + 1;
	}
}

template <class Object>
Object Gcd(Object a , Object b){
	if(b == 0){
		return a;
	}else{
		return Gcd(b , a % b);
	}
}

template <class Object>
Object Loop(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		line(obj[i])
	}
	return obj;
}

template <class Object>
Object Looppair(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		space(obj[i].F , obj[i].S)
	}
	return obj;
}

bool zoe(const pair<ll , ll>& i ,const pair<ll , ll>& j){
	return (i.S > j.S);
}

class Start{

	public :

		ll n , k;
		ll a[MAXX];

		void LOOPER(){
			cin >> n >> k;

			FOR(i ,1 , 1 , n) cin >> a[i];

			slove(a , n , k);

		}

	private :

		void slove(ll a[] , ll n , ll k){

			ll solan = Ceil(n , 2ll);

			ll sum = 0;

			vector<pair<ll , ll> > ve;

			map<ll , ll> mp;

			map<ll , ll> :: iterator it;

			FOR(i , 1 , 1 , n) mp[a[i]]++;

			REN(it , mp){
				ve.pb(make_pair(it->F , it->S));
			}

			sort(ve.begin() , ve.end() , zoe);

			FOR(i , 0 , 1 , leng(ve)){
				if(solan == 0) break;
				if(solan <= Ceil(ve[i].S , 2ll)){
					solan -= solan;
					sum += Ceil(ve[i].S , 2ll);
				}else{
					solan -= Ceil(ve[i].S , 2ll);
					sum += ve[i].S;
				}
			}

			see(sum)

		}

};
Start huy;
void _love(){
	huy.LOOPER();
}
void _nang_am(){
/*
The idea bad is yours

					Or

					The idea good is your

								  		And more importantly

															this code is yours
*/
}
goodluck_code(){
  _love();
  _nang_am();
  R
}


#include <bits/stdc++.h>
#define               ll long long int
#define               usll unsigned long long int
#define               F first
#define               S second
#define               _R return ;
#define               R return 0;
#define               pb push_back
#define               endln "\n"
#define               MAXX 200007
#define               MX 3002
#define               MOD 111539786
#define               PI 3,1415926535897
#define               sps setprecision
#define               leng(s) s.size()-1
#define               lengall(s) s.size()
#define               F0R(i , x , j , n) for(ll i = x ; i >= n ; i -= j)
#define               FOR(i , x , j , n) for(ll i = x ; i <= n ; i += j)
#define               REN(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define               ALL_OF_ME  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define               debug(a) cout << (#a) << " = " << a << "\n";
#define               see(a) cout<< a << "\n";
#define               line(a) cout << a <<" ";
#define               newline cout<< "\n";
#define               space(a,b) cout << a << " " << b << "\n";
#define               goodluck_code() int main()
#define  I_too_stupid_to_solve_a_problem_BUT_I_not_too_stupid_to_realize_who_I_love return 0;
using namespace std;

template <class Object>
Object Reverse(Object obj , ll l , ll r){
	while(l < r) swap(obj[l] , obj[r]), l++ , r--;
}

template <class Object>
Object Swap(Object a , Object b){
	Object tmp = a;
			a = b;
			b = tmp;
}

template <class Object>
Object Ceil(Object a , Object b){
	if(a % b == 0){
		return a / b;
	}else{
		return a / b + 1;
	}
}

template <class Object>
Object Gcd(Object a , Object b){
	if(b == 0){
		return a;
	}else{
		return Gcd(b , a % b);
	}
}

template <class Object>
Object Loop(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		line(obj[i])
	}
	return obj;
}

template <class Object>
Object Looppair(Object obj , ll l , ll r){
	FOR(i , l , 1 , r){
		space(obj[i].F , obj[i].S)
	}
	return obj;
}

class Start{

	public :

		ll n , k;
		ll a[MAXX];

		void LOOPER(){
			cin >> n >> k;

			FOR(i ,1 , 1 , n) cin >> a[i];

			slove(a , n , k);

		}

	private :

		void slove(ll a[] , ll n , ll k){

			ll solan = Ceil(n , 2ll);

			ll sum = 0;

			map<ll , ll> mp;

			map<ll , ll> :: iterator it;

			FOR(i , 1 , 1 , n) mp[a[i]]++;

			REN(it , mp){
				sum += Ceil(it->S , 2ll);
			}

			if(sum == solan) see(n)
			else see(n - 1)
		}

};
Start huy;
void _love(){
	huy.LOOPER();
}
void _nang_am(){
/*
The idea bad is yours

					Or

					The idea good is your

								  		And more importantly

															this code is yours
*/
}
goodluck_code(){
  _love();
  _nang_am();
  R
}


#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int arr[1005];
void solve(int t){
    int n, k;
    cin >> n >> k;
    int inp;
    for(int i = 0 ; i < n ; i++){
    	cin >> inp;
    	arr[inp]++;
    }
    vector <int> v;
    for(int i = 1 ; i <= k ; i++)v.pb(arr[i]);
    sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int allowed = ceil(n*1.0/2.0), ans = 0;
	for(int i = 0 ; i < v.size() ; i++){
		if(allowed == 0)break;
		int curr = ceil(v[i]*1.0/2.0);
		if(curr <= allowed){
			ans += v[i];
			allowed -= curr;
		}
		else {
			ans += 2*(curr-allowed);
			allowed -= curr-allowed;
		}
	}
	if(allowed > 0)ans += allowed;
	cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t ; i++){
        solve(i);
    }
}


#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int arr[1005];
void solve(int t){
    int n, k;
    cin >> n >> k;
    int inp;
    for(int i = 0 ; i < n ; i++){
    	cin >> inp;
    	arr[inp]++;
    }
    vector <int> v;
    for(int i = 1 ; i <= k ; i++)v.pb(arr[i]);
    sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int allowed = ceil(n*1.0/2.0), ans = 0;
	for(int i = 0 ; i < v.size() ; i++){
		if(allowed == 0)break;
		int curr = ceil(v[i]*1.0/2.0);
		if(curr <= allowed){
			ans += v[i];
			allowed -= curr;
		}
		else {
			ans += 2*(curr-allowed);
			allowed = 0;
		}
	}
	cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t ; i++){
        solve(i);
    }
}


#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int arr[1005];
void solve(int t){
    int n, k;
    cin >> n >> k;
    int inp;
    for(int i = 0 ; i < n ; i++){
    	cin >> inp;
    	arr[inp]++;
    }
    vector <int> v;
    for(int i = 1 ; i <= k ; i++)v.pb(arr[i]);
    sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int allowed = ceil(n*1.0/2.0), ans = 0;
	for(int i = 0 ; i < v.size() ; i++){
		if(allowed == 0)break;
		int curr = ceil(v[i]*1.0/2.0);
		if(curr <= allowed){
			ans += v[i];
			allowed -= v[i]/2;
		}
		else {
			ans += 2*allowed;
			allowed -= 0;
		}
	}
	if(allowed > 0)ans += allowed;
	cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t ; i++){
        solve(i);
    }
}


#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int arr[1005];
void solve(int t){
    int n, k;
    cin >> n >> k;
    int inp;
    for(int i = 0 ; i < n ; i++){
    	cin >> inp;
    	arr[inp]++;
    }
    vector <int> v;
    for(int i = 1 ; i <= k ; i++)v.pb(arr[i]);
    sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int allowed = ceil(n*1.0/2.0), ans = 0;
	for(int i = 0 ; i < v.size() ; i++){
		if(allowed == 0)break;
		int curr = ceil(v[i]*1.0/2.0);
		if(curr <= allowed){
			ans += (v[i]/2)*2;
			allowed -= v[i]/2;
		}
		else {
			ans += 2*allowed;
			allowed = 0;
		}
	}
	if(allowed > 0)ans += allowed;
	cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t ; i++){
        solve(i);
    }
}


#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int arr[1005];
void solve(int t){
    int n, k;
    cin >> n >> k;
    int inp;
    for(int i = 0 ; i < n ; i++){
    	cin >> inp;
    	arr[inp]++;
    }
    vector <int> v;
    for(int i = 1 ; i <= k ; i++)v.pb(arr[i]);
    sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	int allowed = ceil(n*1.0/2.0), ans = 0;
	for(int i = 0 ; i < v.size() ; i++){
		if(allowed == 0)break;
		int curr = ceil(v[i]*1.0/2.0);
		if(curr <= allowed){
			ans += v[i];
			allowed -= curr;
		}
		else {
			ans += 2*(curr-allowed);
			allowed -= curr-allowed;
		}
	}
	cout << ans << endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t ; i++){
        solve(i);
    }
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin>>n>>k;
    map<int, int> mp;
    for (int i=0 ; i<n ; i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    int ans=0;
    for (auto it= mp.begin() ; it!=mp.end() ; it++)
    {
        int x= it->first;
        int y=it->second;
        if(y%2==1)
        {
            cout<<n-1<<endl;
            return 0;
        }

    }
    cout<<n<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll n,x ,k ;
vector<pair<ll,ll> > e, o;
map<ll,ll>m;
ll pos ,stu ;
bool cmp( pair < ll,ll > a , pair <ll,ll> b){

    if( a.first != b.first) return ( a.first> b.first   );
    return a.second> b.second ;
}
int main()
{

  cin>>n>>k;
  for(int i=0 ; i<n; i ++){

     cin>>x;
     m[x]++;
  }
  for(auto it:m){

     ll p=(it.second+1) /2 ;
     if(it.second%2==0)  e.pb( { p  , it.first } );
     else o.pb( { p , it.first });
  }
  sort( e.begin () , e.end() , cmp ) ;
  sort( o.begin () , o.end() , cmp) ;
  pos=(n+1)>>1;
  for(int i=0 ; i<e.size() and pos>0 ; i++){

       if(  pos- e[i].first   >=0 ){

           pos=pos-e[i].first;
           stu=stu+m[e[i].second ] ;
       }
       else if(pos>0){

           ll tk=  pos;
           stu+=  min( tk*2  , m[ e[ i ].second ] );
           cout<<stu; return 0;
       }
  }

  for(int i=0 ; i<o.size() and pos>0 ; i++){

    if(  pos- o[i].first   >=0 ){

           pos=pos-o[i].first ;
           stu=stu+m[o[i].second ] ;
       }
       else if ( pos>0){

           ll tk= pos;
        stu+=  min( tk*2  , m[ o[ i ].second ] );
           cout<<stu; return 0;
       }

   }
   cout<<stu;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll n,x ,k ;
vector<pair<ll,ll> > e, o;
map<ll,ll>m;
ll pos ,stu ;
bool cmp( pair < ll,ll > a , pair <ll,ll> b){

    if( a.first != b.first) return ( a.first> b.first   );
    return a.second> b.second ;
}
int main()
{

  cin>>n>>k;
  for(int i=0 ; i<n; i ++){

     cin>>x;
     m[x]++;
  }
  for(auto it:m){

     ll p=(it.second+1) /2 ;
     if(it.second%2==0)  e.pb( { p  , it.first } );
     else o.pb( { p , it.first });
  }
  sort( e.begin () , e.end() , cmp ) ;
  sort( o.begin () , o.end() , cmp) ;
  pos=(n+1)>>1;
  for(int i=0 ; i<e.size() and pos>0 ; i++){

       if(  pos- e[i].first   >=0 ){

           pos=pos-e[i].first;
           stu=stu+m[e[i].second ] ;
       }
       else{

           ll tk= e[i].first - pos;
           stu+=  tk*2 ;
           cout<<stu; return 0;
       }
  }

  for(int i=0 ; i<o.size() and pos>0 ; i++){

    if(  pos- o[i].first   >=0 ){

           pos=pos-o[i].first ;
           stu=stu+m[o[i].second ] ;
       }
       else{

           ll tk= o[i].first - pos;
           stu+=  tk*2  ;
           cout<<stu; return 0;
       }

   }
   cout<<stu;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll n,x ,k ;
vector<pair<ll,ll> > e, o;
map<ll,ll>m;
ll pos ,stu ;
bool cmp( pair < ll,ll > a , pair <ll,ll> b){

    if( a.first != b.first) return ( a.first> b.first   );
    return a.second> b.second ;
}
int main()
{

  cin>>n>>k;
  for(int i=0 ; i<n; i ++){

     cin>>x;
     m[x]++;
  }
  for(auto it:m){

     ll p=(it.second+1) /2 ;
     if(it.second%2==0)  e.pb( { p  , it.first } );
     else o.pb( { p , it.first });
  }
  sort( e.begin () , e.end() , cmp ) ;
  sort( o.begin () , o.end() , cmp) ;
  pos=(n+1)>>1;
  for(int i=0 ; i<e.size() and pos>0 ; i++){

       if(  pos- e[i].first   >=0 ){

           pos=pos-e[i].first;
           stu=stu+m[e[i].second ] ;
       }
       else if(pos>0){

           ll tk= e[i].first - pos;
           stu+=  tk*2 ;
           cout<<stu; return 0;
       }
  }

  for(int i=0 ; i<o.size() and pos>0 ; i++){

    if(  pos- o[i].first   >=0 ){

           pos=pos-o[i].first ;
           stu=stu+m[o[i].second ] ;
       }
       else if ( pos>0){

           ll tk= o[i].first - pos;
           stu+=  tk*2  ;
           cout<<stu; return 0;
       }

   }
   cout<<stu;
}


#include <bits/stdc++.h>

using namespace std;

int main()

{
    int n;

    int k;

    cin>>n>>k;
    map<int, int> mp;
    for (int i=0 ; i<n ; i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    int p=ceil(n/2.0)*2;
    //cout<<p<<endl;
    int ans=0;
    int carr=0;
    for(auto it = mp.begin() ; it != mp.end() ; it ++)
    {
        int x=it->second;
        if (x%2==0){
            ans+=x;
        }
        else {
            ans+=(x-1);
            carr++;
        }
    }
    //cout<<ans<<" "<<carr<<endl;
    if(!carr){
        cout<<n<<endl;
        return 0;
    }

    else {
        p-=ans;
        //cout<<p<<endl;
        while(p>0 and carr>0){
            p-=2;
            ans++;
            carr--;
        }
    }
    cout<<ans<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll n,x ,k ;
vector<pair<ll,ll> > e, o;
map<ll,ll>m;
ll pos ,stu ;
bool cmp( pair < ll,ll > a , pair <ll,ll> b){

    if( a.first != b.first) return ( a.first> b.first   );
    return a.second> b.second ;
}
int main()
{

  cin>>n>>k;
  for(int i=0 ; i<n; i ++){

     cin>>x;
     m[x]++;
  }
  for(auto it:m){

     ll p=(it.second+1) /2 ;
     if(it.second%2==0)  e.pb( { p  , it.first } );
     else o.pb( { p , it.first });
  }
  sort( e.begin () , e.end() , cmp ) ;
  sort( o.begin () , o.end() , cmp) ;
  pos=(n+1)>>1;
  for(int i=0 ; i<e.size() and pos>0 ; i++){

       if(  pos- e[i].first   >0 ){

           pos=pos-e[i].first;
           stu=stu+m[e[i].second ] ;
       }
       else{

           ll tk= e[i].first - pos;
           stu+=  tk*2 ;
           cout<<stu; return 0;
       }
  }

  for(int i=0 ; i<o.size() and pos>0 ; i++){

    if(  pos- o[i].first   >=0 ){

           pos=pos-o[i].first ;
           stu=stu+m[o[i].second ] ;
       }
       else{

           ll tk= o[i].first - pos;
           stu+=  min( tk*2 , m[ o[i].second ] )  ;
           cout<<stu; return 0;
       }

   }
   cout<<stu;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
ll n,x ,k ;
vector<pair<ll,ll> > e, o;
map<ll,ll>m;
ll pos ,stu ;
bool cmp( pair < ll,ll > a , pair <ll,ll> b){

    if( a.first != b.first) return ( a.first> b.first   );
    return a.second> b.second ;
}
int main()
{

  cin>>n>>k;
  for(int i=0 ; i<n; i ++){

     cin>>x;
     m[x]++;
  }
  for(auto it:m){

     ll p=(it.second+1) /2 ;
     if(it.second%2==0)  e.pb( { p  , it.first } );
     else o.pb( { p , it.first });
  }
  sort( e.begin () , e.end() , cmp ) ;
  sort( o.begin () , o.end() , cmp) ;
  pos=(n+1)>>1;
  for(int i=0 ; i<e.size() and pos>0 ; i++){

       if(  pos- e[i].first   >0 ){

           pos=pos-e[i].first;
           stu=stu+m[e[i].second ] ;
       }
       else{

           ll tk= e[i].first - pos;
           stu+=  tk*2 ;
           cout<<stu; return 0;
       }
  }

  for(int i=0 ; i<o.size() and pos>0 ; i++){

    if(  pos- o[i].first   >=0 ){

           pos=pos-o[i].first ;
           stu=stu+m[o[i].second ] ;
       }
       else{

           ll tk= o[i].first - pos;
           stu+=  tk*2  ;
           cout<<stu; return 0;
       }

   }
   cout<<stu;
}


#include <bits/stdc++.h>

using namespace std;

int main()

{
    int n;

    int k;

    cin>>n>>k;
    map<int, int> mp;
    for (int i=0 ; i<n ; i++)
    {
        int x;
        cin>>x;
        mp[x]++;
    }
    int p=ceil(n/2.0)*2;
    //cout<<p<<endl;
    int ans=0;
    int carr=0;
    for(auto it = mp.begin() ; it != mp.end() ; it ++)
    {
        int x=it->second;
        if (x%2==0){
            ans+=x;
        }
        else {
            ans+=(x-1);
            carr++;
        }
    }
    //cout<<ans<<" "<<carr<<endl;
    if(!carr){
        cout<<n<<endl;
    }

    else {
        p-=ans;
        //cout<<p<<endl;
        while(p>0 and carr>0){
            p-=2;
            ans++;
            carr--;
        }
    }
    cout<<ans<<endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n , k;
    cin>>n>>k;
    map<int , int> mp;
    for (int i=0 ;i<n ; i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    int ans=0;
    k*=2;
    int carr=0;
    for (auto it= mp.begin() ; it!=mp.end() ; it++){
        int x= it->first;
        int y=it->second;
        if(y%2==0) ans+=y;

    }
    if(ans>n){
        cout<<n<<endl;
        return 0;
    }
    for (auto it=mp.begin(); it!=mp.end(); it++){
        int x = it->second;
        if(ans+carr>n){
            ans--;
        }
        if(x%2==1){
            ans+=x;
            carr++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e9+7
#define ffr(i,a,b)  for(int i=a;i<b;i++)
#define mem(a,b)  memset( a,b,sizeof a)
#define Max(x,y) y>x?x=y:x=x
int n, k, x;
int a[1050] = {0};
int main() {
    std::ios::sync_with_stdio(false);
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &x);
        a[x]++;
    }
    int num = (n + 1) / 2, ans = 0, f = 0;
    for(int i = 1; i <= n; i++) {
        if(a[i] == 0)
            continue;
        if(a[i]%2==0){
                num-=a[i]/2;
                a[i]=0;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0)
            continue;
        if(f){
            ans+=a[i];
            continue;
        }
        if(a[i]%2){
            if(num>=(a[i]+1)/2){
                num-=(a[i]+1)/2;
                a[i]=0;
            }
            else{
                f=1;
                a[i]-=num*2;
                num=0;
                ans+=max(a[i],0);
            }
        }
    }
    cout<<n-ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,k,x;
int a[105]={0};
int main(){
    cin>>n>>k;
    ll ans=0,num,t=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]%2){
            ans+=(a[i]+1)/2;
        }
        else{
            ans+=a[i]/2;
        }
    }
    num=(n+1)/2;
    //cout<<ans<<endl;
    ans=ans-num;
    //cout<<ans<<endl;
    cout<<n-ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using  namespace std;

int c[1050];
void solve() {
    int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++) {
		int x;
		cin >> x;
		c[x]++;
	}

	int ans = 0;
	int k = (n + 1) / 2;
	for(int i=1;i<= m;i++) {
		k -= c[i] / 2;
		ans += (c[i] / 2) * 2;
	}
	ans += k;
	cout << min(ans, n);
}
int main(){
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e9+7
#define ffr(i,a,b)  for(int i=a;i<b;i++)
#define mem(a,b)  memset( a,b,sizeof a)
#define Max(x,y) y>x?x=y:x=x
int n,k,x;
int a[1050]={0};
bool cmp(int a,int b){
    return a>b;
}
int main()
{
    std::ios::sync_with_stdio(false);
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&x);
        a[x]++;
    }
    int num=(n+1)/2,sum=0,ans=0,f=0;
    sort(a+1,a+1+k,cmp);
    for(int i=1;i<=k;i++){
        if(a[i]%2){
            if(num>=(a[i]+1)/2)
                num-=(a[i]+1)/2;
            else{
                f=i;
                break;
            }
            }
            else{
               if(num>=(a[i]+1)/2)
                num-=(a[i]+1)/2;
            else{
                f=i;
                break;
            }
        }
    }
    if(f){
        ans=a[f]-num*2;
        for(int j=f+1;j<=k;j++){
            ans+=a[j];
        }
        cout<<n-ans<<endl;
    }
    else{
        cout<<n<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,k,x;
int a[1005]={0};
int main(){
    cin>>n>>k;
    ll ans=0,num,t=0;
    for(int i=1;i<=n;i++){
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]%2){
            ans+=(a[i]+1)/2;
        }
        else{
            ans+=a[i]/2;
        }
    }
    num=(n+1)/2;
    //cout<<ans<<endl;
    ans=ans-num;
    //cout<<ans<<endl;
    cout<<n-ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e9+7
#define ffr(i,a,b)  for(int i=a;i<b;i++)
#define mem(a,b)  memset( a,b,sizeof a)
#define Max(x,y) y>x?x=y:x=x
int n, k, x;
int a[1050] = {0};
int main() {
    std::ios::sync_with_stdio(false);
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &x);
        a[x]++;
    }
    int num = (n + 1) / 2, ans = 0, f = 0;
    for(int i = 1; i <= n; i++) {
        if(a[i] == 0)
            continue;
        if(a[i]%2==0){
            if(num>=a[i]/2){
                num-=a[i]/2;
                a[i]=0;
            }
            else{
                a[i]-=num*2;
                f=1;
                break;
            }
        }
    }
    if(f){
        for(int i=1;i<=n;i++){
            ans+=a[i];
        }
        cout<<n-ans<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(f){
            ans+=a[i];
            continue;
        }
      //  if(a[i]%2){
        if(num>(a[i]+1)/2){
            num-=(a[i]+1)/2;
            a[i]=0;
        }
        else{
            f=1;
            a[i]-=num*2;
            num=0;
            ans+=max(a[i],0);
        }
       // }
        /*else{
            if(num>(a[i])/2){
                num-=(a[i])/2;
                a[i]=0;
            }
            else{
                f=1;
            }
        }*/
    }
    cout<<n-ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e9+7
#define ffr(i,a,b)  for(int i=a;i<b;i++)
#define mem(a,b)  memset( a,b,sizeof a)
#define Max(x,y) y>x?x=y:x=x
int n, k, x;
int a[1050] = {0};
int main() {
    std::ios::sync_with_stdio(false);
    scanf("%d%d", &n, &k);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &x);
        a[x]++;
    }
    int num = (n + 1) / 2, ans = 0, f = 0;
    for(int i = 1; i <= n; i++) {
        if(a[i] == 0)
            continue;
        if(a[i]%2==0){
            if(num>=a[i]/2){
                num-=a[i]/2;
                a[i]=0;
            }
            else{
                a[i]-=num*2;
                f=1;
                break;
            }
        }
    }
    if(f){
        for(int i=1;i<=n;i++){
            ans+=a[i];
        }
        cout<<n-ans<<endl;
        return 0;
    }
    for(int i=1;i<=n;i++){
        if(f){
            ans+=a[i];
        }
        if(a[i]%2){
            if(num>(a[i]+1)/2){
                num-=(a[i]+1)/2;
                a[i]=0;
            }
            else{
                f=1;
                a[i]-=num*2;
                ans+=a[i];
            }
        }
        /*else{
            if(num>(a[i])/2){
                num-=(a[i])/2;
                a[i]=0;
            }
            else{
                f=1;
            }
        }*/
    }
    cout<<n-ans<<endl;
    return 0;
}


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,i,c=0;
	cin>>n>>k;
	int a[10000];
	int b[10000];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		b[a[i]]++;
	}
	for(i=1;i<=k;i++)
	{
		c=c+(b[i]%2);
	}
	cout<<n-(c/2);
}

/*#include <stdio.h>
int a[1000];
int main()
{
	int n, k, t, odds = 0;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) {
		scanf("%d", &t);
		a[t-1]++;
	}
	for(int i = 0; i < k; i++)
		odds += a[i]%2;
	printf("%d", n - odds/2);
}*/


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,mn=1000000,i,c=0;
	cin>>n>>k;
	int a[n];
	int b[n];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	//sort(a,a+n);
	for(i=0;i<n;i++)
	{
		b[a[i]]++;
	}
	for(i=1;i<=k;i++)
	{
		c=c+(b[i]%2);
	}
	cout<<n-(c/2);
}


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,i,c=0;
	cin>>n>>k;
	int a[n];
	int b[n];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		b[a[i]]++;
	}
	for(i=1;i<k;i++)
	{
		c=c+(b[i]%2);
	}
	cout<<n-(c/2);
}


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,mn=1000000,i,c=0;
	cin>>n>>k;
	int a[n];
	int b[n];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	for(i=k;i>=1;i--)
	{
		if(a[i]%2)
		{
			cout<<n-1;
			return 0;
			//break;
		}
	}
	cout<<n;
}


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,mn=1000000,i,c=0;
	cin>>n>>k;
	int a[n];
	int b[n];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<(n-n%2);i+=2)
	{
		if(a[i]!=a[i+1])
		{
			c++;
		}
	}
	cout<<n-c;
}


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,mn=1000000,i,c=0;
	cin>>n>>k;
	int a[10000];
	int b[10000];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[a[i]]++;
	}
	for(i=k;i>=1;i--)
	{
		if(b[i]%2)
		{
			cout<<n-1;
			return 0;
			//break;
		}
	}
	cout<<n;
}


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,i,c=0;
	cin>>n>>k;
	int a[10000];
	int b[10000];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		b[a[i]-1]++;
	}
	for(i=0;i<k;i++)
	{
		c=c+(b[i]%2);
	}
	cout<<n-(c/2);
}

/*#include <stdio.h>
int a[1000];
int main()
{
	int n, k, t, odds = 0;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++) {
		scanf("%d", &t);
		a[t-1]++;
	}
	for(int i = 0; i < k; i++)
		odds += a[i]%2;
	printf("%d", n - odds/2);
}*/


//drinks choosing
#include <bits/stdc++.h>
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define pi pair<int,int>
#define mod 1000000007
using namespace std;
int main()
{
	int n,k,i,c=0;
	cin>>n>>k;
	int a[n];
	int b[n];
	memset(b,0,sizeof(b));
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		b[a[i]]++;
	}
	for(i=1;i<=k-(n%2);i++)
	{
		c=c+(b[i]%2);
	}
	cout<<n-(c/2);
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a, c=0;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> even, odd;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            if(cnt[i]%2) odd.push_back(cnt[i]);
            else even.push_back(cnt[i]);
        }
    }
    int x = (n+1)/2, ans=0;
    sort(ALL(even), cmp);
    sort(ALL(odd), cmp);
    //vprint(even);
    //vprint(odd);
    for(int i=0; i<even.size(); i++){
        if(x<=0) break;
        if(x*2 >= even[i]){
            ans += even[i]; x -= even[i]/2;
        }
        else{ans += x*2; x=0;}
    }
    for(int j=0; j<odd.size(); j++){
        ans += (odd[j]/2)*2;
        x -= (odd[j]/2);
        c += (odd[j]%2);
    }

    print(ans+((c+1)/2));
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> even, odd;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            if(cnt[i]%2) odd.push_back(cnt[i]);
            else even.push_back(cnt[i]);
        }
    }
    int x = (n+1)/2, ans=0;
    sort(ALL(even), cmp);
    sort(ALL(odd), cmp);
    //vprint(even);
    //vprint(odd);
    for(int i=0; i<even.size(); i++){
        if(x<=0) break;
        if(x*2 >= even[i]){
            ans += even[i]; x -= even[i]/2;
        }
        else{ans += x*2; x=0;}
    }
    for(int i=0; i<odd.size(); i++){
        if(x<=0) break;
        if(x*2 >= odd[i]){
            ans += odd[i]; x -= (odd[i]+1)/2;
        }
        else{ans += x*2; x=0;}
    }
    //cout << "ans= ";
    print(ans)
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> even, odd;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            if(cnt[i]%2) odd.push_back(cnt[i]);
            else even.push_back(cnt[i]);
        }
    }
    int x = ceil((double)n/2.0), ans=0;
    sort(ALL(even), cmp);
    sort(ALL(odd), cmp);
    //vprint(even);
    //vprint(odd);
    for(int i=0; i<even.size(); i++){
        if(!x) break;
        if(x >= even[i]/2){
            ans += even[i]; x -= even[i]/2;
        }
        else{ans += x*2; x=0;}
    }
    for(int i=0; i<odd.size(); i++){
        if(!x) break;
        if(x >= (odd[i]+1)/2){
            ans += odd[i]; x -= (odd[i]+1)/2;
        }
        else{ans += x*2; x=0;}
    }
    //cout << "ans= ";
    print(ans)
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> even, odd;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            if(cnt[i]%2) odd.push_back(cnt[i]);
            else even.push_back(cnt[i]);
        }
    }
    int x = ceil((double)n/2.0), ans=0;
    sort(ALL(even), cmp);
    sort(ALL(odd), cmp);
    vprint(even);
    vprint(odd);
    for(int i=0; i<even.size(); i++){
        if(!x) break;
        if(x >= even[i]/2){
            ans += even[i]; x -= even[i]/2;
        }
        else{ans += x*2; x=0;}
    }
    for(int i=0; i<odd.size(); i++){
        if(!x) break;
        if(x >= (odd[i]+1)/2){
            ans += odd[i]; x -= (odd[i]+1)/2;
        }
        else{ans += x*2; x=0;}
    }
    //cout << "ans= ";
    print(ans)
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(pair<int, int> a, pair<int, int> b){ return (a.first*a.second)>(b.first*b.second);}

void solve(int tc){
    int n, k, a;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> even, odd;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            if(cnt[i]%2) odd.push_back(cnt[i]);
            else even.push_back(cnt[i]);
        }
    }
    int x = ceil((double)n/2.0), ans=0;
    //vprint(even);
    //vprint(odd);
    for(int i=0; i<even.size(); i++){
        if(!x) break;
        if(x >= even[i]/2){
            ans += even[i]; x -= even[i]/2;
        }
        else{ans += x*2; x=0;}
    }
    for(int i=0; i<odd.size(); i++){
        if(!x) break;
        if(x >= (odd[i]+1)/2){
            ans += odd[i]; x -= (odd[i]+1)/2;
        }
        else{ans += x*2; x=0;}
    }
    //cout << "ans= ";
    print(ans)
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a, c=0, ans=0;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    for(pair<int, int> ip : cnt){
        ans += (ip.second/2)*2;
        c += (ip.second%2);
    }

    print(ans+((c+1)/2));
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> num;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            num.push_back(cnt[i]);
        }
    }
    int x = (n+1)/2, ans=0;
    sort(ALL(num), cmp);
    //vprint(num);
    for(int i=0; i<num.size(); i++){
        if(x<=0) break;
        if(x*2<num[i]){
            ans += x*2;
            break;
        }
        ans += num[i];
        x -= ((num[i]+1)/2);
    }
    //cout << "ans= ";
    print(ans)
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#define lli long long int
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define ALL(x) x.begin(), x.end()
#define print(x) cout<<x<<"\n";
#define cases(x, y) for(int x=1; x<=y; x++)
#define PI acos(-1.0)
#define maxiii(a, b, c) max(max(a, b), c)
#define miniii(a, b, c) min(min(a, b), c)
#define nl cout<<"\n"
#define point(x) fixed<<setprecision(x)
#define printcase(c, n) cout << "Case " << c << ": " << n <<endl
#define printcaseii(c, n, m) cout << "Case " << c << ": " << n << " " << m <<endl
#define vprint(vec) for(int i=0; i<vec.size(); i++){cout << vec[i] << " ";} cout<<endl
#define aprint(ar, n) for(int i=0; i<n; i++){cout << ar[i] << " ";}cout<<endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define execution_time nl;nl;print(point(8)<<"**Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC<<"fs");
#define INPUT freopen("input.txt", "r", stdin)
#define OUTPUT freopen("output.txt", "w", stdout)
using namespace std;
lli findLCM(lli a, lli b){return ((a*b)/__gcd(a,b));}
lli input(){lli x; cin >> x; return x;}
int digitCNT(int n){return ceil(log10(n)+0.00000001);}
bool cmp(int a, int b){ return a>b;}

void solve(int tc){
    int n, k, a;
    cin >> n >> k;
    map<int, int> cnt;
    for(int i=0; i<n; i++){
        cin >> a;
        cnt[a]++;
    }
    vector<int> num;
    for(int i=1; i<=k; i++){
        if(cnt[i]){
            num.push_back(cnt[i]);
        }
    }
    int x = (n+1)/2, ans=0;
    sort(ALL(num), cmp);
    //vprint(num);
    for(int i=0; i<num.size(); i++){
        if(x<=0) break;
        if(x*2<=num[i]){
            ans += x*2;
            break;
        }
        ans += num[i];
        x -= ((num[i]+1)/2);
    }
    //cout << "ans= ";
    print(ans)
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        //INPUT;
        //OUTPUT;
    #endif

    int tc = 1;
    //cin >> tc; //TEST CASE
    for(int i=1; i<=tc; i++){
        solve(i);
    }

    #ifndef ONLINE_JUDGE
        execution_time;
    #endif
    return EXIT_SUCCESS;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}

	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}

	for(int i = 0; i < n; i++){
		if(max > 0){
			sum+=arr1[i]/2*2;
			max-=arr1[i]/2;
		}else{
			continue;
		}

	}

	if(max>=0){
		sum+=max;
	}else{
		sum-=2*-max;
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}
	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}
	for(int i = 0; i < t; i++){
		while(arr1[i]>0 && max > 0){
			if(arr1[i] - 2 == -1){
				break;
			}else{
				arr1[i]-=2;
				sum+=2;
			}
			max--;
		}
	}
	if(max > 0){
		sum+=max;
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={0};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}
	int max=(t+1)/2;

	for(int i = 0; i < t; i++){
		while(arr1[i]>=2 && max > 0){
			arr1[i]-=2;
			sum+=2;
			max--;
		}
		if(max<=0){
			break;
		}
	}
	if(max == 0){
		printf("%d", sum);
	}else{
		printf("%d", sum + max);
	}

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={0};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang]++;
	}
	int max=(t+1)/2;

	for(int i = 1; i <= t; i++){
		while(arr1[i]>=2 && max > 0){
			arr1[i]-=2;
			sum+=2;
			max--;
		}
		if(max<=0){
			break;
		}
	}
	if(max == 0){
		printf("%d", sum);
	}else{
		printf("%d", sum + max);
	}

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}

	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}
	int cnt=0;
	for(int i = 0; i < t; i++){
		sum+=arr1[i]/2*2;
		cnt+=arr1[i]%2;
	}

	sum+=(cnt+1)/2;
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[t]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}
	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}
	for(int i = 0; i < t; i++){
		while(arr1[i]>0 && max != 0){
			if(arr1[i] - 2 == -1){
				break;
			}else{
				arr1[i]-=2;
				sum+=2;
			}
			max--;
		}
	}
	if(max != 0){
		sum+=max;
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[t+1]={};
	for(int i = 1; i <= t; i++){
		scanf("%d", &ang);
		arr1[ang]++;
	}
	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}
	for(int i = 0; i < t; i++){
		while(arr1[i]>0 && max != 0){
			if(arr1[i] - 2 == -1){
				break;
			}else{
				arr1[i]-=2;
				sum+=2;
			}
			max--;
		}
	}
	if(max != 0){
		sum+=max;
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}
	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}
	for(int i = 0; i < t; i++){
		while(arr1[i]>0 && max != 0){
			if(arr1[i] - 2 == -1){
				break;
			}else{
				arr1[i]-=2;
				sum+=2;
			}
			max--;
		}
	}
	if(max != 0){
		sum+=max;
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[t]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}

	int max;
	if(t%2==0){
		max=t/2;
	}else{
		max=t/2+1;
	}

	for(int i = 0; i < t; i++){
		if(max > 0){
			sum+=arr1[i]/2*2;
			max-=arr1[i]/2;
		}else{
			continue;
		}

	}

	if(max>=0){
		sum+=max;
	}else{
		sum-=2*-max;
	}
	printf("%d", sum);

	return 0;
}


#include <stdio.h>

int main(){
	int t, n, sum=0;
	scanf("%d %d", &t, &n);
	int ang, arr1[1001]={};
	for(int i = 0; i < t; i++){
		scanf("%d", &ang);
		arr1[ang-1]++;
	}
	int max=(t+1)/2;

	for(int i = 0; i < n; i++){
		sum+=arr1[i]/2*2;
		cnt+=arr1[i]%2;
		max--;
	}

	sum+=cnt;
	printf("%d", sum);

	return 0;
}


#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>
#include <cstdio>
#include <numeric>
#include <cstdlib>
#include <cassert>
#include <set>
#include <ctime>
#include <stack>
#include <cstring>
#include<functional>
#include <sstream>
#include <ctype.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#pragma comment(linker, "/STACK:16777216")
template<typename T> T fac(T a) { return a ? a*fac(a - 1) : 1; }
template<typename T> T power(T a, int p) { return !p ? 1 : (p & 1 ? a*power(a, p - 1) : power(a*a, p >> 1)); }
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return b / gcd(a, b) * a; }
template<typename T> T next() { T _; cin >> _; return _; }
template<> int next<int>() { int _; scanf("%d", &_); return _; }
template<> double next<double>() { double _; scanf("%lf", &_); return _; }
template<> ll next<ll>() { ll _; scanf("%lld", &_); return _; }
template<typename E> vector<E> next(int n) { vector<E> res(n); for (int i = 0; i < n; i++) res[i] = next<E>(); return res; }
template<class C, class E> int count(const C &c, const E &e) { return count(c.begin(), c.end(), e); }
template<class E> bool has(const vector<E> &c, const E &e) { return find(c.begin(), c.end(), e) != c.end(); }
template<class E> int find(const vector<E> &c, const E &e) { return find(c.begin(), c.end(), e) - c.begin(); }
template<class E> bool binary_has(const vector<E> &c, const E &e) { return binary_search(c.begin(), c.end(), e); }
template<class E> int binary_find(const vector<E> &c, const E &e) { return lower_bound(c.begin(), c.end(), e) - c.begin(); }
template<typename T> T dist2(T i1, T j1, T i2, T j2) { return (i1 - i2)*(i1 - i2) + (j1 - j2)*(j1 - j2); }
bool ok(int i, int j, int n, int m) { return 0 <= i&&i<n && 0 <= j&&j<m; }
const double EPS = 1e-9;
const double PI = acos(-1);
bool LE(double a, double b) { return b - a > -EPS; }
bool BE(double a, double b) { return a - b > -EPS; }
bool EQ(double a, double b) { return fabs(a - b) < EPS; }
bool LESS(double a, double b) { return b - a > EPS; }
bool BIGG(double a, double b) { return a - b > EPS; }
template <int N, typename T> class lug { public: T at[N]; };

int main()
{
	int n = next<int>();
	auto v = next<int>(n);
	auto b = next<int>(n);

	int cycles = 0;
	vector<bool> used(n);
	for (int i = 0; i < n; i++)
	{
		if (!used[i])
		{
			cycles++;
			for (int j = i;; j = v[j] - 1)
			{
				if (used[j]) break;
				used[j] = true;
			}
		}
	}

	int bum = 0;
	for (int i = 0; i < n; i++)
		bum += b[i];

	cout << (cycles - 1) * 2 + 1 - bum % 2 << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>
#include <cstdio>
#include <numeric>
#include <cstdlib>
#include <cassert>
#include <set>
#include <ctime>
#include <stack>
#include <cstring>
#include<functional>
#include <sstream>
#include <ctype.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#pragma comment(linker, "/STACK:16777216")
template<typename T> T fac(T a) { return a ? a*fac(a - 1) : 1; }
template<typename T> T power(T a, int p) { return !p ? 1 : (p & 1 ? a*power(a, p - 1) : power(a*a, p >> 1)); }
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return b / gcd(a, b) * a; }
template<typename T> T next() { T _; cin >> _; return _; }
template<> int next<int>() { int _; scanf("%d", &_); return _; }
template<> double next<double>() { double _; scanf("%lf", &_); return _; }
template<> ll next<ll>() { ll _; scanf("%lld", &_); return _; }
template<typename E> vector<E> next(int n) { vector<E> res(n); for (int i = 0; i < n; i++) res[i] = next<E>(); return res; }
template<class C, class E> int count(const C &c, const E &e) { return count(c.begin(), c.end(), e); }
template<class E> bool has(const vector<E> &c, const E &e) { return find(c.begin(), c.end(), e) != c.end(); }
template<class E> int find(const vector<E> &c, const E &e) { return find(c.begin(), c.end(), e) - c.begin(); }
template<class E> bool binary_has(const vector<E> &c, const E &e) { return binary_search(c.begin(), c.end(), e); }
template<class E> int binary_find(const vector<E> &c, const E &e) { return lower_bound(c.begin(), c.end(), e) - c.begin(); }
template<typename T> T dist2(T i1, T j1, T i2, T j2) { return (i1 - i2)*(i1 - i2) + (j1 - j2)*(j1 - j2); }
bool ok(int i, int j, int n, int m) { return 0 <= i&&i<n && 0 <= j&&j<m; }
const double EPS = 1e-9;
const double PI = acos(-1);
bool LE(double a, double b) { return b - a > -EPS; }
bool BE(double a, double b) { return a - b > -EPS; }
bool EQ(double a, double b) { return fabs(a - b) < EPS; }
bool LESS(double a, double b) { return b - a > EPS; }
bool BIGG(double a, double b) { return a - b > EPS; }
template <int N, typename T> class lug { public: T at[N]; };

int main()
{
	int n = next<int>();
	auto v = next<int>(n);
	auto b = next<int>(n);

	int cycles = 0;
	vector<bool> used(n);
	for (int i = 0; i < n; i++)
	{
		if (!used[i])
		{
			cycles++;
			for (int j = i;; j = v[j] - 1)
			{
				if (used[j]) break;
				used[j] = true;
			}
		}
	}

	int bum = 0;
	for (int i = 0; i < n; i++)
		bum += b[i];

	if (cycles == 1)
	{
		cout << 1 - bum % 2 << endl;
	}
	else
	{
		cout << cycles + 1 - bum % 2 << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int par[200000];
int p[200000];

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
}

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) par[i] = i;
    REP (i,n) {
        scanf("%d",&p[i]);
        unite(i,p[i]-1);
    }
    int x = 1;
    REP (i,n) {
        int b;
        scanf("%d",&b);
        x ^= b;
    }
    set<int> st;
    REP (i,n) st.insert(find(i));
    int ans = 2 * (st.size()-1) + x;
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int par[200000];
int p[200000];

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    par[x] = y;
}

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) par[i] = i;
    REP (i,n) {
        scanf("%d",&p[i]);
        unite(i,p[i]-1);
    }
    int x = 1;
    REP (i,n) {
        int b;
        scanf("%d",&b);
        x ^= b;
    }
    set<int> st;
    REP (i,n) st.insert(find(i));
    int ans = x;
    if (st.size() > 1) ans += st.size();
    printf("%d\n",ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const double pi=acos(-1.0);
const double eps=1e-9;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define re return
#define vi vector <int>
#define pii pair <int,int>
#define pll pair <long long , long long>
#define task
#define file freopen("task.in","r",stdin);freopen("task.out","w",stdout)
#define inp freopen("input.txt","r",stdin)
#define outp freopen("output.txt","w",stdout)
typedef long long ll;

const int N = (int)2e5+5;

int b,c,n,p,cnt;
bool was[N];
vi v[N];

void dfs(int x)
{
	was[x] = true;
	for(int i=0;i<v[x].size();i++)
		if(!was[v[x][i]])dfs(v[x][i]);
}

int main()
{
	ios:: sync_with_stdio(false);
	//inp;outp;
	//file;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> p;
		p--;
		v[i].pb(p);
	}
	for(int i=0;i<n;i++)
	{
		cin >> b;
		c+=b;
	}
	for(int i=0;i<n;i++)
		if(!was[i])
		{
			//cout << i << endl;
			cnt++;
			dfs(i);
		}
	if(cnt == 1)
	{
		cout << (c+1)%2;
		return 0;
	}
	cout << cnt+(c+1)%2;
	//cout << cnt << b << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const double pi=acos(-1.0);
const double eps=1e-9;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define re return
#define vi vector <int>
#define pii pair <int,int>
#define pll pair <long long , long long>
#define task
#define file freopen("task.in","r",stdin);freopen("task.out","w",stdout)
#define inp freopen("input.txt","r",stdin)
#define outp freopen("output.txt","w",stdout)
typedef long long ll;

const int N = (int)2e5+5;

int b,c,n,p,cnt;
bool was[N];
vi v[N];

void dfs(int x)
{
	was[x] = true;
	for(int i=0;i<v[x].size();i++)
		if(!was[v[x][i]])dfs(v[x][i]);
}

int main()
{
	ios:: sync_with_stdio(false);
	//inp;outp;
	//file;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> p;
		p--;
		v[i].pb(p);
	}
	for(int i=0;i<n;i++)
	{
		cin >> b;
		c+=b;
	}
	for(int i=0;i<n;i++)
		if(!was[i])
		{
			//cout << i << endl;
			cnt++;
			dfs(i);
		}
	cout << (cnt-1)*2+(c+1)%2;
	//cout << cnt << b << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <random>

using namespace std;

typedef long long ll;

mt19937 rnd(218);
const int INF = 1e9, MAXN = 1e5;
const ll INFll = 1e18;

int ans = 0;
vector<int> arr(MAXN + 1), been(MAXN + 1);

void dfs(int now) {
    if (been[now])
        return;

    been[now] = 1;
    dfs(arr[now]);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        arr[i]--;
    }

    int sums = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        sums += x;
    }

    for (int i = 0; i < n; ++i) {
        if (!been[i]) {
            dfs(i);
            ans++;
        }
    }
    int s = 0;
    for (int i = 0; i < n; ++i) {
        s = arr[s];
    }
    if (ans == 1 && s == 0) {
        ans = 0;
        if (!(sums != n && sums > 0)) {
            ans++;
        }

        cout << ans << endl;
        return 0;
    }

    if (!(sums != n && sums > 0)) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <random>

using namespace std;

typedef long long ll;

mt19937 rnd(218);
const int INF = 1e9, MAXN = 1e5;
const ll INFll = 1e18;

int ans = 0;
vector<int> arr(MAXN + 1), been(MAXN + 1);

void dfs(int now) {
    if (been[now])
        return;

    been[now] = 1;
    dfs(arr[now]);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        arr[i]--;
    }

    int sums = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        sums += x;
    }

    for (int i = 0; i < n; ++i) {
        if (!been[i]) {
            dfs(i);
            ans++;
        }
    }
    int s = 0;
    for (int i = 0; i < n; ++i) {
        s = arr[s];
    }
    if (ans == 1 && s == 0) {
        ans = 0;
        if (sums % 2 == 0) {
            ans++;
        }

        cout << ans << endl;
        return 0;
    }

    if (sums % 2 == 0) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <random>

using namespace std;

typedef long long ll;

mt19937 rnd(218);
const int INF = 1e9, MAXN = 2e5;
const ll INFll = 1e18;

int ans = 0;
vector<int> arr(MAXN + 1), been(MAXN + 1);

void dfs(int now) {
    if (been[now])
        return;

    been[now] = 1;
    dfs(arr[now]);
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        arr[i]--;
    }

    int sums = 0;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        sums += x;
    }

    for (int i = 0; i < n; ++i) {
        if (!been[i]) {
            dfs(i);
            ans++;
        }
    }
    int s = 0;
    for (int i = 0; i < n; ++i) {
        s = arr[s];
    }
    if (ans == 1 && s == 0) {
        ans = 0;
        if (sums % 2 == 0) {
            ans++;
        }

        cout << ans << endl;
        return 0;
    }

    if (sums % 2 == 0) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MAX 200002
int n;

int p[MAX];

int cnt = 0;

int deg[MAX];

vector<int> v[MAX];
vector<int> r[MAX];

vector<pair<int, int> > vv;
bool us[MAX];

inline void dfs(int b, int &ord,int pr=-1){
	us[b] = true;
	for (int i = 0; i < v[b].size(); i++){
		if (us[v[b][i]]==false){
			dfs(v[b][i], ord, b);
		}
	}
	vv.push_back(make_pair(ord, b));
	ord++;
}
bool used[MAX];

vector<int> nods[MAX];

inline void rdfs(int b,int be){
	used[b] = true;
	nods[be].push_back(b);
	for (int i = 0; i < r[b].size(); i++){
		if (used[r[b][i]] == false){
			rdfs(r[b][i],be);
		}
	}
}
int main(){
	cin >> n;
	int self = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		v[i].push_back(p[i]-1);
		r[p[i] - 1].push_back(i);
		if (p[i] == i + 1){
			self++;
		}
	}
	for (int i = 0; i < n; i++){
		int b;
		scanf("%d", &b);
		cnt ^= b;
	}
	int ans = 0;
	if (cnt == 0){
		ans++;
	}
	int ord = 0;
	for (int i = 0; i < n; i++){
		if (us[i]==false)
		dfs(i, ord);
	}
	int be = 0;
	sort(vv.begin(), vv.end(), greater<pair<int, int> >());
	for (int i = 0; i < vv.size(); i++){
		if (used[vv[i].second] == false){
			rdfs(vv[i].second,be);
			be++;
		}
	}
	if (be > 1){
		for (int i = 0; i < be; i++){
			if (nods[i].size() > 1){
				int cnt = 0;
				for (int j = 0; j < nods[i].size(); j++){
					int go = nods[i][j];
					if (r[go].size() > 1){
						cnt += r[go].size()-1;
					}
				}
				if (cnt){
					ans += cnt;
				}
				else{
					ans++;
				}
			}
		}
	}
	ans += self;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MAX 200002
int n;

int p[MAX];

int cnt = 0;

int deg[MAX];

vector<int> v[MAX];
vector<int> r[MAX];

vector<pair<int, int> > vv;
bool us[MAX];

inline void dfs(int b, int &ord,int pr=-1){
	us[b] = true;
	for (int i = 0; i < v[b].size(); i++){
		if (us[v[b][i]]==false){
			dfs(v[b][i], ord, b);
		}
	}
	vv.push_back(make_pair(ord, b));
	ord++;
}
bool used[MAX];

vector<int> nods[MAX];

inline void rdfs(int b,int be){
	used[b] = true;
	nods[be].push_back(b);
	for (int i = 0; i < r[b].size(); i++){
		if (used[r[b][i]] == false){
			rdfs(r[b][i],be);
		}
	}
}
int main(){
	cin >> n;
	int self = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		v[i].push_back(p[i]-1);
		r[p[i] - 1].push_back(i);
		if (p[i] == i + 1){
			self++;
		}
	}
	if (n == 1){
		if (b[0] == 0){
			puts("1");
			return 0;
		}
		puts("0");
		return 0;
	}
	for (int i = 0; i < n; i++){
		int b;
		scanf("%d", &b);
		cnt ^= b;
	}
	int ans = 0;
	if (cnt == 0){
		ans++;
	}
	int ord = 0;
	for (int i = 0; i < n; i++){
		if (us[i]==false)
		dfs(i, ord);
	}
	int be = 0;
	sort(vv.begin(), vv.end(), greater<pair<int, int> >());
	for (int i = 0; i < vv.size(); i++){
		if (used[vv[i].second] == false){
			rdfs(vv[i].second,be);
			be++;
		}
	}
	if (be > 1){
		for (int i = 0; i < be; i++){
			if (nods[i].size() > 1){
				int cnt = 0;
				for (int j = 0; j < nods[i].size(); j++){
					int go = nods[i][j];
					if (r[go].size() > 1){
						cnt += r[go].size()-1;
					}
				}
				if (cnt){
					ans += cnt;
				}
				else{
					ans++;
				}
			}
		}
	}
	ans += self;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define MAX 200002
int n;

int p[MAX];

int cnt = 0;

int deg[MAX];

vector<int> v[MAX];
vector<int> r[MAX];

vector<pair<int, int> > vv;
bool us[MAX];

inline void dfs(int b, int &ord,int pr=-1){
	us[b] = true;
	for (int i = 0; i < v[b].size(); i++){
		if (us[v[b][i]]==false){
			dfs(v[b][i], ord, b);
		}
	}
	vv.push_back(make_pair(ord, b));
	ord++;
}
bool used[MAX];

vector<int> nods[MAX];

inline void rdfs(int b,int be){
	used[b] = true;
	nods[be].push_back(b);
	for (int i = 0; i < r[b].size(); i++){
		if (used[r[b][i]] == false){
			rdfs(r[b][i],be);
		}
	}
}
int main(){
	cin >> n;
	int self = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		v[i].push_back(p[i]-1);
		r[p[i] - 1].push_back(i);
		if (p[i] == i + 1){
			self++;
		}
	}
	for (int i = 0; i < n; i++){
		int b;
		scanf("%d", &b);
		cnt ^= b;
	}
	int ans = 0;
	if (cnt == 0){
		ans++;
	}
	if (n == 1){
		cout << ans << endl;
		return 0;
	}
	int ord = 0;
	for (int i = 0; i < n; i++){
		if (us[i]==false)
		dfs(i, ord);
	}
	int be = 0;
	sort(vv.begin(), vv.end(), greater<pair<int, int> >());
	for (int i = 0; i < vv.size(); i++){
		if (used[vv[i].second] == false){
			rdfs(vv[i].second,be);
			be++;
		}
	}
	if (be > 1){
		for (int i = 0; i < be; i++){
			if (nods[i].size() > 1){
				int cnt = 0;
				for (int j = 0; j < nods[i].size(); j++){
					int go = nods[i][j];
					if (r[go].size() > 1){
						cnt += r[go].size()-1;
					}
				}
				if (cnt){
					ans += cnt;
				}
				else{
					ans++;
				}
			}
		}
	}
	ans += self;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;

int n;
int p[maxn];
int b[maxn];
char used[maxn];

void dfs(int v) {
    if (used[v]) return;
    used[v] = true;
    dfs(p[v]);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i]; --p[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            ++ans;
            dfs(i);
        }
    }
    if (ans == 1) ans = 0;

    ans += 1 - accumulate(b, b + n, 0) % 2;
    cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;

int n;
int p[maxn];
int b[maxn];
char used[maxn];

void dfs(int v) {
    if (used[v]) return;
    used[v] = true;
    dfs(p[v]);
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i]; --p[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            ++ans;
            dfs(i);
        }
    }
    if (ans == 1) ans = 0;

    ans += 1 - accumulate(b, b + n, 0) % 2;
    cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;

int n;
int p[maxn];
int b[maxn];
char used[maxn];
vector<int> graph[maxn];
int degree[maxn];

int dfs(int v) {
    if (used[v]) return 0;
    used[v] = true;
    int c = 1 - degree[v];
    for (auto u: graph[v]) {
        c += dfs(u);
    }
    return c;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i]; --p[i];
        graph[i].push_back(p[i]);
        degree[p[i]] = 1;
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

    int ans = 1 - accumulate(b, b + n, 0) % 2;
    ans -= 2;
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            int t = dfs(i);
            ans += max(1 + t, 2);
        }
    }

    cout << ans << '\n';
}


#include <iostream>
#include <stack>
using namespace std;
const int N  = 2e5+5;
int P[N];
int A[N];
stack<int> st;
int visited[N];
void dfs(int v)  {
    visited[v]=1;
    if(!visited[P[v]])  {
        dfs(P[v]);
    }
    st.push(v);
}

void dfs2(int v)    {
    visited[v]=1;
    if(!visited[A[v]])  dfs2(A[v]);
}

int main() {
    int n;scanf("%d",&n);
    int ans=0;
    for (int i=1; i<=n; i++) {
        scanf("%d",P+i);
        A[P[i]]=i;
    }
    int sm = 0,x;
    for (int i=1; i<=n; i++) {
        scanf("%d",&x);sm+=x;
    }
    if(sm==0)   ans++;
    for (int i=1; i<=n; i++) {
        if(!visited[i]) dfs(i);
    }
    for (int i=1; i<=n; i++) {
        visited[i]=0;
    }
    int ans2=0;
    while (!st.empty()) {
        if(!visited[st.top()])  {
            ans2++;dfs2(st.top());
        }
        st.pop();
    }
    if(ans2>1) {
        ans+=ans2;
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <stack>
using namespace std;
const int N  = 2e5+5;
int P[N];
int A[N];
stack<int> st;
int visited[N];
void dfs(int v)  {
    visited[v]=1;
    if(!visited[P[v]])  {
        dfs(P[v]);
    }
    st.push(v);
}

void dfs2(int v)    {
    visited[v]=1;
    if(!visited[A[v]])  dfs2(A[v]);
}

int main() {
    int n;scanf("%d",&n);
    int ans=0;
    for (int i=1; i<=n; i++) {
        scanf("%d",P+i);
        A[P[i]]=i;
    }
    int sm = 0,x;
    for (int i=1; i<=n; i++) {
        scanf("%d",&x);sm+=x;
    }
    if(sm==0 || sm==n)   ans++;
    for (int i=1; i<=n; i++) {
        if(!visited[i]) dfs(i);
    }
    for (int i=1; i<=n; i++) {
        visited[i]=0;
    }
    int ans2=0;
    while (!st.empty()) {
        if(!visited[st.top()])  {
            ans2++;dfs2(st.top());
        }
        st.pop();
    }
    if(ans2>1) {
        ans+=ans2;
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <stack>
using namespace std;
const int N  = 2e5+5;
int P[N];
int A[N];
stack<int> st;
int visited[N];
void dfs(int v)  {
    visited[v]=1;
    if(!visited[P[v]])  {
        dfs(P[v]);
    }
    st.push(v);
}

void dfs2(int v)    {
    visited[v]=1;
    if(!visited[A[v]])  dfs2(A[v]);
}

int main() {
    int n;scanf("%d",&n);
    int ans=0;
    for (int i=1; i<=n; i++) {
        scanf("%d",P+i);
        A[P[i]]=i;
    }
    int sm = 0,x;
    for (int i=1; i<=n; i++) {
        scanf("%d",&x);sm+=x;
    }
    if(sm%2==0)   ans++;
    for (int i=1; i<=n; i++) {
        if(!visited[i]) dfs(i);
    }
    for (int i=1; i<=n; i++) {
        visited[i]=0;
    }
    int ans2=0;
    while (!st.empty()) {
        if(!visited[st.top()])  {
            ans2++;dfs2(st.top());
        }
        st.pop();
    }
    if(ans2>1) {
        ans+=ans2;
    }
    cout<<ans<<endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define TASKNAME ""

void solve(int test_number);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(9);
    cerr.setf(ios::fixed);
    cerr.precision(3);
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#else
#endif
    int n = 1;
    for (int i = 0; i < n; i++) {
        solve(i);
    }
}

const int MAX_N = 200005;

int n, p[MAX_N], b[MAX_N];

void solve(int test_number) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        --p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    bool vis[MAX_N] = {false};
    int cyc = 0;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            cyc++;
            for (int j = p[i]; j != i; j = p[j]) {
                vis[j] = true;
            }
        }
    }
    cout  << ((cyc > 1)? cyc: 0) + ((count(b, b + n, 0) == n)? 1: 0) << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define TASKNAME ""

void solve(int test_number);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(9);
    cerr.setf(ios::fixed);
    cerr.precision(3);
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#else
#endif
    int n = 1;
    for (int i = 0; i < n; i++) {
        solve(i);
    }
}

const int MAX_N = 200005;

int n, p[MAX_N], b[MAX_N];

void solve(int test_number) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        --p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    bool vis[MAX_N] = {false};
    int cyc = 0;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            int len = 0;
            for (int j = i; !vis[j]; j = p[j]) {
                len++;
                vis[j] = true;
            }
            cyc++;
        }
    }
    cout  << ((cyc > 1)? cyc: 0) + ((count(b, b + n, 1) & 1)? 0: 1) << endl;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define TASKNAME ""

void solve(int test_number);

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(9);
    cerr.setf(ios::fixed);
    cerr.precision(3);
#ifdef LOCAL
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#else
#endif
    int n = 1;
    for (int i = 0; i < n; i++) {
        solve(i);
    }
}

const int MAX_N = 200005;

int n, p[MAX_N], b[MAX_N];

void solve(int test_number) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        --p[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    bool vis[MAX_N] = {false};
    int cyc = 0;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            cyc++;
            for (int j = i; !vis[j]; j = p[j]) {
                vis[j] = true;
            }
        }
    }
    cout  << ((cyc > 1)? cyc: 0) + ((count(b, b + n, 0) == n)? 1: 0) << endl;
}


#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    scanf("%d", &n);
    int p[n], b[n];
    rep(i, 0, n)
    {
        scanf("%d", &p[i]);
        p[i]--;
    }
    rep(i, 0, n)
        scanf("%d", &b[i]);
    vector<bool> used(n, false);
    int cnt = 0;
    rep(i, 0, n)
        if (!used[i])
        {
            cnt++;
            int x = i;
            while (true)
            {
                used[x] = true;
                if (p[x] == i)
                    break;
                x = p[x];
            }
        }
    int cnt1 = 0;
    rep(i, 0, n)
        cnt1 += b[i];
    int ans = 0;
    if (cnt > 1)
        ans += cnt;
    if (cnt1 % 2 == 0)
        ans++;
    printf("%d\n", ans);
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 1000000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("battleship.out", "w", stdout);
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    //cout.precision(20);
    //int TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    scanf("%d", &n);
    int p[n], b[n];
    rep(i, 0, n)
    {
        scanf("%d", &p[i]);
        p[i]--;
    }
    rep(i, 0, n)
        scanf("%d", &b[i]);
    vector<bool> used(n, false);
    int cnt = 0;
    rep(i, 0, n)
        if (!used[i])
        {
            cnt++;
            int x = i;
            while (true)
            {
                used[x] = true;
                if (p[x] == i)
                    break;
                x = p[x];
            }
        }
    int cnt1 = 0;
    rep(i, 0, n)
        cnt1 += b[i];
    if (cnt1 & 1)
        printf("%d", (cnt - 1) * 2);
    else
        printf("%d", (cnt - 1) * 2 + 1);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <functional>
#include <bitset>
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
#define sz(a) (int)a.size()
#define pb push_back
const int MAXN = 2 * 1000 * 1000 + 10;
const double EPS = 1e-9;
typedef long long LL;
const LL MOD = 1000 * 1000 * 1000 + 7;

int main(int argc, char* argv[]) {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	//freopen("numbers.in", "r", stdin); freopen("numbers.out", "w", stdout);
#endif

	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	vector<int> p(n);
	forn(i, 0, n) {
		cin >> p[i]; p[i]--;
	}

	vector<int> b(n);
	int sum_b = 0;
	forn(i, 0, n) {
		cin >> b[i];
		sum_b += b[i];
	}

	if (n == 1) {
		if (b[0] == 1) {
			cout << 0;
		}
		else {
			cout << 1;
		}
		return 0;
	}

	int ans = 0;

	ans += (sum_b + 1) % 2;

	vector<int> self;
	for (int i = 0; i < n; ++i) {
		if (p[i] == i) self.push_back(i);
	}

	for (int i = 0; i < self.size(); ++i) {
		p[self[(i + 1) % (int)self.size()]] = self[i];
		ans++;
	}

	vector<char> used(n);
	for (int i = 0; i < n; ++i) {
		if (used[i]) continue;

		ans+=2;
		int v = i;
		while (!used[v]) {
			used[v] = true;
			v = p[v];
		}
	}

	ans -= 2;
	cout << ans;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <functional>
#include <bitset>
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
#define sz(a) (int)a.size()
#define pb push_back
const int MAXN = 2 * 1000 * 1000 + 10;
const double EPS = 1e-9;
typedef long long LL;
const LL MOD = 1000 * 1000 * 1000 + 7;

int main(int argc, char* argv[]) {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	//freopen("numbers.in", "r", stdin); freopen("numbers.out", "w", stdout);
#endif

	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	vector<int> p(n);
	forn(i, 0, n) {
		cin >> p[i]; p[i]--;
	}

	vector<int> b(n);
	int sum_b = 0;
	forn(i, 0, n) {
		cin >> b[i];
		sum_b += b[i];
	}

	int ans = 0;

	ans += (sum_b + 1) % 2;

	vector<char> used(n);
	for (int i = 0; i < n; ++i) {
		if (used[i]) continue;

		ans+=2;
		int v = i;
		while (!used[v]) {
			used[v] = true;
			v = p[v];
		}
	}

	ans -= 2;
	cout << ans;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <cstdio>
#include <map>
#include <unordered_map>
#include <string>
#include <iomanip>
#include <vector>
#include <memory.h>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <functional>
#include <bitset>
using namespace std;
#define mems(A, val) memset(A, val, sizeof(A))
#define mp(a, b) make_pair(a, b)
#define all(B) (B).begin(), (B).end()
#define forn(it, from, to) for(int it = from; it < to; ++it)
#define forit (it, coll) for(auto it = coll.begin(); it != coll.end(); ++it)
#define sz(a) (int)a.size()
#define pb push_back
const int MAXN = 2 * 1000 * 1000 + 10;
const double EPS = 1e-9;
typedef long long LL;
const LL MOD = 1000 * 1000 * 1000 + 7;

int main(int argc, char* argv[]) {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	//freopen("numbers.in", "r", stdin); freopen("numbers.out", "w", stdout);
#endif

	ios::sync_with_stdio(0);

	int n;
	cin >> n;
	vector<int> p(n);
	forn(i, 0, n) {
		cin >> p[i]; p[i]--;
	}

	vector<int> b(n);
	int sum_b = 0;
	forn(i, 0, n) {
		cin >> b[i];
		sum_b += b[i];
	}

	if (n == 1) {
		if (b[0] == 1) {
			cout << 0;
		}
		else {
			cout << 1;
		}
		return 0;
	}

	int ans = 0;

	ans += (sum_b + 1) % 2;

	vector<char> used(n);
	for (int i = 0; i < n; ++i) {
		if (used[i]) continue;

		ans++;
		int v = i;
		while (!used[v]) {
			used[v] = true;
			v = p[v];
		}
	}

	cout << ans;

	return 0;
}