#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <array>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000 + 5;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-7;
const int MAX = 2e5 + 5;



int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i] > b[i]) {
			swap(a[i], b[i]);
		}
	}
	map<int, vector<int>> m;
	for (int i = 0; i < n; i++) {
		m[a[i]].emplace_back(i);
		m[b[i]].emplace_back(i);
	}
	map<int, int> cnt;
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	for (auto it = m.begin(); it != m.end(); it++) {
		pq.push(make_pair(it->second.size(), it->first));
		cnt[it->first] = it->second.size();
	}
	vector<int> isUsed(n);
	set<int> checkedColors;
	int ans = 0;
	while (!pq.empty()) {
		int c = pq.top().second;
		int size = pq.top().first;
		

		pq.pop();
		if (checkedColors.find(c) != checkedColors.end()) {
			continue;
		}
		for (int mi : m[c]) {
			
			if (isUsed[mi]) {
				continue;
			}

			isUsed[mi] = true;
			pq.push(make_pair(--cnt[a[mi]], a[mi]));
			
			pq.push(make_pair(--cnt[b[mi]], b[mi]));
			ans++;
			break;
		}
		checkedColors.insert(c);

	}
	cout << ans << endl;
}


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

const int Max = 200001;

int main(){
  int n;
  cin >> n;
  
  vector<int> vec(n);
  for(int& nvec:vec) cin >> nvec;
  
  vector<vector<int>> from(Max);
  for(int i=0;i<n/2;i++){
    from[vec[i]].emplace_back(vec[n-1-i]);
    from[vec[n-1-i]].emplace_back(vec[i]);
  }
  
  queue<int> que;
  vector<bool> memo(Max,false);
  
  int ans=0;
  //vecの値でまわす
  for(int nvec:vec){
    if(memo[nvec]) continue;
    int cou = 0;
    que.push(nvec);
    cou++;
    memo[nvec]=true;
    //連結している部分をみる
    while(que.size()){
      int q;
      q = que.front();que.pop();
      for(int p:from[q]){
        if(memo[p]) continue;
        que.push(p);
        cou++;
        memo[p]=true;
      }
    }
    ans+=cou-1;
  }
  cout << ans << endl;
}