#include <bits/stdc++.h>
#ifdef LOCAL_TEST
  #pragma comment(linker, "/stack:16777216")
#endif

using namespace std;

typedef long long int ll;
typedef vector <ll> vll;
typedef pair<ll, ll> pp;
typedef vector<pp > vpp;
typedef stack < pair<int, int> > sii;
typedef queue < ll > qll;

#define sz(a) (ll) ((a).size())
#define pb push_back
#define mp(a, b)       (make_pair(a, b) )
#define all(c)        (c).begin(),(c).end()
#define sortA(v)      (sort(v.begin(), v.end()))
#define sortD(v)      (sort(v.rbegin(), v.rend()))
#define fill(a)       (memset(a, 0, sizeof (a)))
#define fillA(a)       (memset(a, -1, sizeof (a)))
#define rep(i,n)     for(ll i=0;i<(n);++i)
#define repA(i,a,n) for(ll i=a;i<=(n);++i)
#define repD(i,a,n) for(ll i=a;i>=(n);--i)
#define pq(x)			    priority_queue<x,std::vector<x>,compare>
#define rpq(x)			  priority_queue<x,std::vector<x>,Rcompare>
const long double PI = 3.141592653589793238462643383;
#define X first
#define Y second

// Functions
struct Rcompare{bool operator()(pp lhs,pp rhs){return lhs.X>rhs.X;}};
struct compare{bool operator()(pp lhs,pp rhs){return lhs.X<rhs.X;}};
// clock_t tm=clock();void fin(){tm=clock()-tm;cerr<<(float)(tm)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

ll power(ll x,ll y)
{
  if(y==0)return 1;
  ll tmp=power(x,y/2);
  if(y%2==1)return ((tmp*tmp)*x);
  return (tmp*tmp);
}
const int MAX = 10009;
const int MOD = 1e9+7;

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifdef LOCAL_TEST
    ifstream cin("in.txt");ofstream cout("out.txt");//tm=clock();
    #endif

	ll n;cin>>n;
	ll m=Ceil(n,2);
	//cout<<m<<'\n';
	pp a[MAX];
	map<ll,ll> mp,mp2;
	ll cnt[MAX]={0},up[MAX]={0},k=0;
	rep(i,n)
	{
		cin>>a[i].X>>a[i].Y;
		if(mp.find(a[i].X)==mp.end())mp[a[i].X]=k,mp2[k]=a[i].X,k++;
		if(mp.find(a[i].Y)==mp.end())mp[a[i].Y]=k,mp2[k]=a[i].Y,k++;
		up[mp[a[i].X]]++;
		if(a[i].X==a[i].Y)cnt[mp[a[i].X]]++;
		else cnt[mp[a[i].X]]++,cnt[mp[a[i].Y]]++;
	}
	ll d[4],ii=0;
	rep(i,k)if(cnt[i]>=m)d[ii]=i,ii++;
	//cout<<ii<<'\n';
	ll mm=1e17;
	rep(i,ii)mm=min(mm,m-up[d[i]]);//cout<<d[i]<<' '<<up[d[i]]<<'\n';
	cout<<mm;

    return 0;
}


/*
    Name: Mohit Khare
    CSE - MNNIT Allahabad
    never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define speed ios_base::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<endl;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
#define PI 3.1415926535897932384626
#define mod 1000000007

const ll linf=99999999999999999ll;
const int maxn=1e6+100;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

vector<int> v;
map< int, pii > m;

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin >> n;

    rep(i,n)
    {
        int a,b;
        cin >> a >> b;
        m[a].fi++;
        if(a != b)
        m[b].se++;
    }

    map< int, pii > :: iterator it = m.begin();
    for(it = m.begin();it!=m.end();it++)
    {
        int val = it->fi;
        int up = m[val].fi;
        int dwn = m[val].se;
        if(up+dwn >= ((n+1)/2))
        {
            // cout << up << " " << dwn << endl;
            if(up >= ((n+1)/2))
            {
                cout<<"0\n";
                return 0;
            }
            v.push_back(min(dwn,(n+1)/2 - up));
        }
    }
    sort(v.begin(),v.end());
    if(v.size() == 0)
        cout<<"-1\n";
    else
    cout << v[0] << endl;
    return 0;
}


/*
    Name: Mohit Khare
    CSE - MNNIT Allahabad
    never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define speed ios_base::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<endl;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
#define PI 3.1415926535897932384626
#define mod 1000000007

const ll linf=99999999999999999ll;
const int maxn=1e6+100;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

vector<int> v;
map< int, pii > m;

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin >> n;

    rep(i,n)
    {
        int a,b;
        cin >> a >> b;
        m[a].fi++;
        m[b].se++;
    }

    map< int, pii > :: iterator it = m.begin();
    for(it = m.begin();it!=m.end();it++)
    {
        int val = it->fi;
        int up = m[val].fi;
        int dwn = m[val].se;
        if(up+dwn >= ((n+1)/2))
        {
            // cout << up << " " << dwn << endl;
            if(up >= ((n+1)/2))
            {
                cout<<"0\n";
                return 0;
            }
            v.push_back(dwn);
        }
    }
    sort(v.begin(),v.end());
    if(v.size() == 0)
        cout<<"-1\n";
    else
    cout << v[0] << endl;
    return 0;
}


/*
    Name: Mohit Khare
    CSE - MNNIT Allahabad
    never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define speed ios_base::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<endl;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
#define PI 3.1415926535897932384626
#define mod 1000000007

const ll linf=99999999999999999ll;
const int maxn=1e6+100;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

vector<int> v;
map< int, pii > m;

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin >> n;

    rep(i,n)
    {
        int a,b;
        cin >> a >> b;
        m[a].fi++;
        m[b].se++;
    }

    map< int, pii > :: iterator it = m.begin();
    for(it = m.begin();it!=m.end();it++)
    {
        int val = it->fi;
        int up = m[val].fi;
        int dwn = m[val].se;
        if(up+dwn >= ((n+1)/2))
        {
            // cout << up << " " << dwn << endl;
            if(up >= ((n+1)/2))
            {
                cout<<"0\n";
                return 0;
            }
            v.push_back(dwn);
        }
    }
    sort(v.begin(),v.end());
    cout << v[0] << endl;
    return 0;
}


/*
    Name: Mohit Khare
    CSE - MNNIT Allahabad
    never give up!!
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define speed ios_base::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,a,b) for(int i=a;i<b;i++)
#define revr(i,a,b) for(int i=a;i>b;i--)
#define pr1(a) cout<<a<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<endl;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
#define PI 3.1415926535897932384626
#define mod 1000000007

const ll linf=99999999999999999ll;
const int maxn=1e6+100;

ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

vector<int> v;
map< int, pii > m;

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    cin >> n;

    rep(i,n)
    {
        int a,b;
        cin >> a >> b;
        m[a].fi++;
        if(a != b)
        m[b].se++;
    }

    map< int, pii > :: iterator it = m.begin();
    for(it = m.begin();it!=m.end();it++)
    {
        int val = it->fi;
        int up = m[val].fi;
        int dwn = m[val].se;
        if(up+dwn >= ((n+1)/2))
        {
            // cout << up << " " << dwn << endl;
            if(up >= ((n+1)/2))
            {
                cout<<"0\n";
                return 0;
            }
            v.push_back(dwn);
        }
    }
    sort(v.begin(),v.end());
    if(v.size() == 0)
        cout<<"-1\n";
    else
    cout << v[0] << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

int n,a,b,ans;
pair<int,int> arr[100001];
map<int,int> frn;
map<int,int> bck;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ans=1e5+1;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        frn[a]++;
        bck[b]++;
        if(a==b){
            bck[b]--;
        }
        arr[i]=make_pair(a,b);
    }
    for(int i=0; i<n; i++){
        if(frn[arr[i].first]+bck[arr[i].first]>=(n+1)/2){
            if(frn[arr[i].first]>=(n+1)/2){
                ans=0;
            }
            else{
                ans=min(ans,(n+1)/2-frn[arr[i].first]);
            }
        }
        if(frn[arr[i].second]+bck[arr[i].second]>=(n+1)/2){
            if(frn[arr[i].second]>=(n+1)/2){
                ans=0;
            }
            else{
                ans=min(ans,(n+1)/2-frn[arr[i].second]);
            }
        }
    }
    if(ans==1e5+1){
        cout << -1 << "\n";
    }
    else{
        cout << ans << "\n";
    }

}


#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

int n,a,b,ans;
pair<int,int> arr[100001];
map<int,int> frn;
map<int,int> bck;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ans=1e5;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        frn[a]++;
        bck[b]++;
        arr[i]=make_pair(a,b);
    }
    for(int i=0; i<n; i++){
        if(frn[arr[i].first]+bck[arr[i].first]>=(n+1)/2){
            if(frn[arr[i].first]>=(n+1)/2){
                ans=0;
            }
            else{
                ans=min(ans,(n+1)/2-frn[arr[i].first]);
            }
        }
        if(frn[arr[i].second]+bck[arr[i].second]>=(n+1)/2){
            if(frn[arr[i].second]>=(n+1)/2){
                ans=0;
            }
            else{
                ans=min(ans,(n+1)/2-frn[arr[i].second]);
            }
        }
    }
    cout << ans << "\n";

}


#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

int n,a,b,ans;
pair<int,int> arr[100001];
map<int,int> frn;
map<int,int> bck;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ans=1e5+1;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        frn[a]++;
        bck[b]++;
        arr[i]=make_pair(a,b);
    }
    for(int i=0; i<n; i++){
        if(frn[arr[i].first]+bck[arr[i].first]>=(n+1)/2){
            if(frn[arr[i].first]>=(n+1)/2){
                ans=0;
            }
            else{
                ans=min(ans,(n+1)/2-frn[arr[i].first]);
            }
        }
        if(frn[arr[i].second]+bck[arr[i].second]>=(n+1)/2){
            if(frn[arr[i].second]>=(n+1)/2){
                ans=0;
            }
            else{
                ans=min(ans,(n+1)/2-frn[arr[i].second]);
            }
        }
    }
    if(ans==1e5+1){
        cout << -1 << "\n";
    }
    else{
        cout << ans << "\n";
    }

}


#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

int n,a,b,ans;
pair<int,int> arr[100001];
map<int,int> frn;
map<int,int> bck;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ans=1e5;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        frn[a]++;
        bck[b]++;
        arr[i]=make_pair(a,b);
    }
    for(int i=0; i<n; i++){
        if(frn[arr[i].first]+bck[arr[i].first]>=(n+1)/2){
            ans=min(ans,bck[arr[i].first]);
        }
        if(frn[arr[i].second]+bck[arr[i].second]>=(n+1)/2){
            ans=min(ans,bck[arr[i].second]);
        }
    }
    cout << ans << "\n";

}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int d[n];
    unordered_map<int,int> f;
    unordered_map<int,int> s;
    for(int i=0;i<n;i++)
    {
        int k,l;
        cin>>k>>l;
        d[i]=k; f[k]++; s[l]++;
    }  int mid=(n+1)/2;  int flag=0;  int mi=n;
    for(int i=0;i<n;i++)
    {  int t=d[i];
            if(f[t]+s[t]>=mid) { flag++; if (f[t]>=mid) mi=0; else { if(mid-f[t]<mi) mi=mid-f[t];     }           }

    }
    if (flag==0) cout<<-1<<endl;
     else cout<<mi<<endl;

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int d[2*n+4];
    unordered_map<long long int,long long int> f;
    unordered_map<long long int,long long int> s;
    for(int i=0;i<2*n;i++)
    {
        long long int k,l;
        cin>>k>>l;
        d[i]=k; d[++i]=l; f[k]++; s[l]++;
    }  long long int mid=(n+1)/2;  long long int flag=0;  long long int mi=3*n;
    for(int i=0;i<2*n;i++)
    {  long long int t=d[i];
            if(f[t]+s[t]>=mid) { flag++; if (f[t]>=mid) mi=0; else { if(mid-f[t]<mi) mi=mid-f[t];     }           }

    }
    if (flag==0) cout<<-1<<endl;
     else cout<<mi<<endl;
   //  cout<<f[1000];

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef __int64 LL;

int main()
{
    int N;
    while (~scanf("%d",&N))
    {
        LL x,y;
        map<LL,LL>m1,m2;
        map<LL,LL>::iterator itt;
        set<LL>s;
        set<LL>::iterator it;
        for (int i = 0;i < N;i++)
        {
            scanf("%I64d%I64d",&x,&y);
            m1[x]++;
            if (x != y)
            {
                m2[y]++;
            }
            s.insert(x);
            s.insert(y);
        }
        LL res = INF;
        LL tmp = (N+1)/2;
        for (it = s.begin();it != s.end();it++)
        {
            x = *it;
            if (m1[x] + m2[x] >= tmp)
            {
                res = min(res,max(0LL,tmp - m1[x]));
            }
        }
        if(res == INF)
        {
            res = -1;
        }
        printf("%I64d\n",res);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int d[n];
    unordered_map<long long int,long long int> f;
    unordered_map<long long int,long long int> s;
    for(int i=0;i<n;i++)
    {
        long long int k,l;
        cin>>k>>l;
        d[i]=k; f[k]++; s[l]++;
    }  long long int mid=(n+1)/2;  long long int flag=0;  long long int mi=n;
    for(int i=0;i<n;i++)
    {  long long int t=d[i];
            if(f[t]+s[t]>=mid) { flag++; if (f[t]>=mid) mi=0; else { if(mid-f[t]<mi) mi=mid-f[t];     }           }

    }
    if (flag==0) cout<<-1<<endl;
     else cout<<mi<<endl;

    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int d[2*n+4];
    unordered_map<long long int,long long int> f;
    unordered_map<long long int,long long int> s;
    for(int i=0;i<2*n;i++)
    {
        long long int k,l;
        cin>>k>>l;
        d[i]=k; d[++i]=l; f[k]++; s[l]++;
    }  long long int mid=(n+1)/2;  long long int flag=0;  long long int mi=n;
    for(int i=0;i<2*n;i++)
    {  long long int t=d[i];
            if(f[t]+s[t]>=mid) { flag++; if (f[t]>=mid) mi=0; else { if(mid-f[t]<mi) mi=mid-f[t];     }           }

    }
    if (flag==0) cout<<-1<<endl;
     else cout<<mi<<endl;

    return 0;
}


/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(i=1;i<=n;i++)
#define   FOR(i,a,b)      for(i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
LL n,i,j,ans = (LL)1E18;
map<LL,LL> fr,ba ;
map<LL,LL> same ;
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ;
    LL tar = (n+1)/2 ;
    LL x,y ;
    REP(i,n)
    { cin>>x>>y,fr[x]++,ba[y]++ ;
      if(x==y)  same[x]++ ;
    }
    for(auto i:fr)
    {  if(i.S>=tar)  return cout<<0,0 ;
       x = ba[i.F] - 1 * same[i.F] ;
       if(i.S+x<tar)  continue ;
       ans = min(ans,tar-i.S) ;
    }
    for(auto i:ba)
    {  x = i.S - 1*same[i.F] ;
       if(x>=tar-fr[i.F]) ans = min(tar-fr[i.F],ans) ;
    }
    if(ans<(LL)1E18)
    cout<<ans ;
    else cout<<-1 ;
}
// Check for 1,0, and other corner cases.


/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(i=1;i<=n;i++)
#define   FOR(i,a,b)      for(i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
LL n,i,j,ans = (LL)1E18;
map<LL,LL> fr,ba ;
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ;
    LL tar = (n+1)/2 ;
    LL x,y ;
    REP(i,n)  cin>>x>>y,fr[x]++,ba[y]++ ;
    for(auto i:fr)
    {  if(i.S>=tar)  return cout<<0,0 ;
       if(i.S+ba[i.F]<tar)  continue ;
       ans = min(ans,tar-i.S) ;
    }
    for(auto i:ba)
     if(i.S>=tar-fr[i.F]) ans = min(tar-fr[i.F],ans) ;
    if(ans<(LL)1E18)
    cout<<ans ;
    else cout<<-1 ;
}
// Check for 1,0, and other corner cases.


/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(i=1;i<=n;i++)
#define   FOR(i,a,b)      for(i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
LL n,i,j,ans = (LL)1E18;
map<LL,LL> fr,ba ;
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ;
    LL tar = (n+1)/2 ;
    LL x,y ;
    REP(i,n)  cin>>x>>y,fr[x]++,ba[y]++ ;
    for(auto i:fr)
    {  if(i.S>=tar)  return cout<<0,0 ;
       if(i.S+ba[i.F]<tar)  continue ;
       ans = min(ans,tar-i.S) ;
    }
    for(auto i:ba)
     if(i.S>=tar-fr[i.F]) ans = min(tar-fr[i.F],ans) ;
    cout<<ans ;
}
// Check for 1,0, and other corner cases.


/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(i=1;i<=n;i++)
#define   FOR(i,a,b)      for(i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
LL n,i,j,ans = (LL)1E18;
map<LL,LL> fr,ba ;
map<LL,LL> same ;
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ;
    LL tar = (n+1)/2 ;
    LL x,y ;
    REP(i,n)
    { cin>>x>>y,fr[x]++,ba[y]++ ;
      if(x==y)  same[x] = 1 ;
    }
    for(auto i:fr)
    {  if(i.S>=tar)  return cout<<0,0 ;
       x = ba[i.F] - 1 * same[i.F] ;
       if(i.S+x<tar)  continue ;
       ans = min(ans,tar-i.S) ;
    }
    for(auto i:ba)
    {  x = i.S - 1*same[i.F] ;
       if(x>=tar-fr[i.F]) ans = min(tar-fr[i.F],ans) ;
    }
    if(ans<(LL)1E18)
    cout<<ans ;
    else cout<<-1 ;
}
// Check for 1,0, and other corner cases.


#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define gold 0

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define freopen(x) freopen(x".in", "r", stdin), freopen (x".out", "w", stdout);
#define ex exit(0)

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

typedef long long ll;
typedef pair<int, int> pii;

const int N = (int) 1e6 + 7;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 2e9;
const ll BIG = 1e18;

int main() {
	fast_io;
	map<int, int> f, s;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		f[x]++, s[y]++;
	}
	int ans = INF, need = n / 2 + (n % 2);
	for (auto x : f) {
		int ff = f[x.fi], ss = s[x.fi];
		//cout << x.fi << ' ' << ff << ' ' << ss << '\n';
		if (ff + ss >= need) {
			if (ff >= need || ss >= need) {
				ans = 0;
				continue;
			}
			int get = need - ff;
			if (ss >= get)
				ans = min(ans, get);
		}
	}
	if (ans == INF)
		cout << -1;
	else
		cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define gold 0

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define freopen(x) freopen(x".in", "r", stdin), freopen (x".out", "w", stdout);
#define ex exit(0)

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

typedef long long ll;
typedef pair<int, int> pii;

const int N = (int) 1e6 + 7;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 2e9;
const ll BIG = 1e18;

int main() {
	fast_io;
	map<int, int> f, s;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		if (x != y)
			f[x]++, s[y]++;
		else
			f[x]++;
	}
	int ans = INF, need = n / 2 + (n % 2);
	for (auto x : f) {
		int ff = f[x.fi], ss = s[x.fi];
		//cout << x.fi << ' ' << ff << ' ' << ss << '\n';
		if (ff + ss >= need) {
			if (ff >= need || ss >= need) {
				ans = 0;
				continue;
			}
			int get = need - ff;
			if (ss >= get)
				ans = min(ans, get);
		}
	}
	if (ans == INF)
		cout << -1;
	else
		cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define gold 0

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define freopen(x) freopen(x".in", "r", stdin), freopen (x".out", "w", stdout);
#define ex exit(0)

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

typedef long long ll;
typedef pair<int, int> pii;

const int N = (int) 1e6 + 7;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 2e9;
const ll BIG = 1e18;

int main() {
	fast_io;
	map<int, int> f, s;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		if (x != y)
			f[x]++, s[y]++;
		else
			f[x]++;
	}
	int ans = INF, need = n / 2 + (n % 2);
	for (auto x : f) {
		int ff = f[x.fi], ss = s[x.fi];
		//cout << x.fi << ' ' << ff << ' ' << ss << '\n';
		if (ff + ss >= need) {
			if (ff >= need) {
				ans = 0;
				continue;
			}
			int get = need - ff;
			if (ss >= get)
				ans = min(ans, get);
		}
	}
	if (ans == INF)
		cout << -1;
	else
		cout << ans;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define gold 0

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define freopen(x) freopen(x".in", "r", stdin), freopen (x".out", "w", stdout);
#define ex exit(0)

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

typedef long long ll;
typedef pair<int, int> pii;

const int N = (int) 1e6 + 7;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 2e9;
const ll BIG = 1e18;

int main() {
	fast_io;
	map<int, int> f, s;
	set<int> q;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, y;
		cin >> x >> y;
		q.insert(x), q.insert(y);
		if (x != y)
			f[x]++, s[y]++;
		else
			f[x]++;
	}
	int ans = INF, need = n / 2 + (n % 2);
	for (auto x : q) {
		int ff = f[x], ss = s[x];
		if (ff + ss >= need) {
			if (ff >= need) {
				ans = 0;
				continue;
			}
			int get = need - ff;
			if (ss >= get)
				ans = min(ans, get);
		}
	}
	if (ans == INF)
		cout << -1;
	else
		cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX 300005

lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
lli gcd(lli a,lli b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
lli min(lli a,lli b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
lli power(lli x,lli n)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x);
        }
        x=(x*x);
        n=n/2;
    }
    return  res;
}

lli factorialNumInverse[1000001];
lli naturalNumInverse[1000001];
lli fact[1000001];

void InverseofNumber(lli n,lli p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (lli i = 2; i <= n; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(lli n,lli p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (lli i = 2; i <= n; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(lli n,lli p)
{
    fact[0] = 1;
    for (lli i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
lli nCrModp(lli n, lli r, lli p)
{
    lli ans = ((fact[n] * factorialNumInverse[r]) % p * factorialNumInverse[n - r]) % p;
    return ans;
}

lli n,k;
lli limit;
lli arr[MAX];
lli f[MAX];
lli b[MAX];
set<lli> s_c;
map<lli,set<lli> > fnt;
map<lli ,set<lli> > bck;
map<lli ,set<lli> > same;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   //lli tc;
   // cin>>tc;
    factorial(200005,mod);
    InverseofNumber(200005,mod);
    InverseofFactorial(200005,mod);
    //while(tc--)
    //{

        cin>>n;
        limit=(n+1)/2;
        for(int i=0;i<n;i++)
        {
            cin>>f[i]>>b[i];
            s_c.insert(f[i]);
            s_c.insert(b[i]);
            fnt[f[i]].insert(i);
            bck[b[i]].insert(i);
            if(f[i]==b[i])
            {
                same[f[i]].insert(i);
            }
        }
        lli l=0;
        lli r=n;
        lli ans=LONG_MAX;

        for(auto it=s_c.begin();it!=s_c.end();it++)
        {
            lli color=*it;
            lli d=max(0,limit-fnt[color].size());
            lli av=bck[color].size()-same[color].size();
            if(av<d)
            {
                continue;
            }
            ans=min(ans,d);

        }

        if(ans==LONG_MAX)
        {
            cout<<-1<<"\n";
            return 0;
        }
        cout<<ans<<"\n";

    //}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX 300005

lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
lli gcd(lli a,lli b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
lli min(lli a,lli b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
lli power(lli x,lli n)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x);
        }
        x=(x*x);
        n=n/2;
    }
    return  res;
}

lli factorialNumInverse[1000001];
lli naturalNumInverse[1000001];
lli fact[1000001];

void InverseofNumber(lli n,lli p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (lli i = 2; i <= n; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(lli n,lli p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (lli i = 2; i <= n; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(lli n,lli p)
{
    fact[0] = 1;
    for (lli i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
lli nCrModp(lli n, lli r, lli p)
{
    lli ans = ((fact[n] * factorialNumInverse[r]) % p * factorialNumInverse[n - r]) % p;
    return ans;
}

lli n,k;
lli limit;
lli arr[MAX];
lli f[MAX];
lli b[MAX];
map<lli,set<lli> > fnt;
map<lli ,set<lli> > bck;
map<lli ,set<lli> > same;
bool check(lli x)
{
    lli res=LONG_MAX;
    for(int i=0;i<n;i++)
    {
        lli color=f[i];
       // cout<<"color :"<<color<<"\n";
        lli d=limit-fnt[color].size();
        //cout<<"remain :"<<d<<"\n";
        if(d<=0)
        {
            return true;
        }
        lli av=bck[color].size()-same[color].size();
        //cout<<"avilable :"<<av<<"\n";
        if(av>=d)
        {
            if(x>=d)
            {
               return true;
            }
        }

    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   //lli tc;
   // cin>>tc;
    factorial(200005,mod);
    InverseofNumber(200005,mod);
    InverseofFactorial(200005,mod);
    //while(tc--)
    //{

        cin>>n;
        limit=(n+1)/2;
        for(int i=0;i<n;i++)
        {
            cin>>f[i]>>b[i];
            fnt[f[i]].insert(i);
            bck[b[i]].insert(i);
            if(f[i]==b[i])
            {
                same[f[i]].insert(i);
            }
        }
        lli l=0;
        lli r=n;
        lli ans=LONG_MAX;
        while(l<=r)
        {
            lli mid=(l+r)/2;
           // cout<<l<<" "<<r<<" "<<mid<<"\n";
            if(check(mid))
            {
                ans=min(ans,mid);
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        if(ans==LONG_MAX)
        {
            cout<<-1<<"\n";
            return 0;
        }
        cout<<ans<<"\n";

    //}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX 300005

lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
lli gcd(lli a,lli b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
lli min(lli a,lli b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
lli power(lli x,lli n)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x);
        }
        x=(x*x);
        n=n/2;
    }
    return  res;
}

lli factorialNumInverse[1000001];
lli naturalNumInverse[1000001];
lli fact[1000001];

void InverseofNumber(lli n,lli p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (lli i = 2; i <= n; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(lli n,lli p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (lli i = 2; i <= n; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(lli n,lli p)
{
    fact[0] = 1;
    for (lli i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
lli nCrModp(lli n, lli r, lli p)
{
    lli ans = ((fact[n] * factorialNumInverse[r]) % p * factorialNumInverse[n - r]) % p;
    return ans;
}

lli n,k;
lli limit;
lli arr[MAX];
lli f[MAX];
lli b[MAX];
set<lli> s_c;
map<lli,set<lli> > fnt;
map<lli ,set<lli> > bck;
map<lli ,set<lli> > same;
bool check(lli x)
{
    lli res=LONG_MAX;
    for(auto it=s_c.begin();it!=s_c.end();it++)
    {
        lli color=*it;
       // cout<<"color :"<<color<<"\n";
        lli d=limit-fnt[color].size();
        //cout<<"remain :"<<d<<"\n";
        if(d<=0)
        {
            return true;
        }
        lli av=bck[color].size()-same[color].size();
        //cout<<"avilable :"<<av<<"\n";
        if(av>=d)
        {
            if(x>=d)
            {
               return true;
            }
        }

    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   //lli tc;
   // cin>>tc;
    factorial(200005,mod);
    InverseofNumber(200005,mod);
    InverseofFactorial(200005,mod);
    //while(tc--)
    //{

        cin>>n;
        limit=(n+1)/2;
        for(int i=0;i<n;i++)
        {
            cin>>f[i]>>b[i];
            s_c.insert(f[i]);
            s_c.insert(b[i]);
            fnt[f[i]].insert(i);
            bck[b[i]].insert(i);
            if(f[i]==b[i])
            {
                same[f[i]].insert(i);
            }
        }
        lli l=0;
        lli r=n;
        lli ans=LONG_MAX;
        while(l<=r)
        {
            lli mid=(l+r)/2;
           // cout<<l<<" "<<r<<" "<<mid<<"\n";
            if(check(mid))
            {
                ans=min(ans,mid);
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        if(ans==LONG_MAX)
        {
            cout<<-1<<"\n";
            return 0;
        }
        cout<<ans<<"\n";

    //}
    return 0;
}


#include <cstdio>
#include <iostream>
#include <map>

#define oo 2000000000

using namespace std;

map<long,long> hash;

struct case1
{
 long a,b;
}cards[200005]={0};

int main()
{
 long n,i,j;
 long ans=oo;

 scanf("%ld",&n);

 for(i=1;i<=n;i++)
   {
    scanf("%ld%ld",&cards[i].a,&cards[i].b);
    hash[cards[i].a]++;
    if(cards[i].a!=cards[i].b)
     hash[cards[i].b]++;
   }

 for(map<long,long>::iterator p=hash.begin();p!=hash.end();p++)
   if(p->second>=(n+1)/2)
    {
     long s=(n+1)/2;
     for(i=1;i<=n;i++)
       s-=cards[i].a==p->first;
     ans=min(ans,max(s,0L));
    }

 if(ans==oo)
  cout<<-1<<endl;
 else
  cout<<ans<<endl;

 return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX 300005

lli max(lli a,lli b)
{
   if(a>b)
   {
       return a;
   }
   return b;
}
lli gcd(lli a,lli b)
{
    if(a==0)
    {
        return b;
    }
    return gcd(b%a,a);
}
lli min(lli a,lli b)
{
   if(a<b)
   {
       return a;
   }
   return b;
}
lli power(lli x,lli n)
{
    lli res=1;
    while(n>0)
    {
        if(n%2==1)
        {
            res=(res*x);
        }
        x=(x*x);
        n=n/2;
    }
    return  res;
}

lli factorialNumInverse[1000001];
lli naturalNumInverse[1000001];
lli fact[1000001];

void InverseofNumber(lli n,lli p)
{
    naturalNumInverse[0] = naturalNumInverse[1] = 1;
    for (lli i = 2; i <= n; i++)
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;
}
void InverseofFactorial(lli n,lli p)
{
    factorialNumInverse[0] = factorialNumInverse[1] = 1;

    for (lli i = 2; i <= n; i++)
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;
}
void factorial(lli n,lli p)
{
    fact[0] = 1;
    for (lli i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % p;
    }
}
lli nCrModp(lli n, lli r, lli p)
{
    lli ans = ((fact[n] * factorialNumInverse[r]) % p * factorialNumInverse[n - r]) % p;
    return ans;
}

lli n,k;
lli limit;
lli arr[MAX];
lli f[MAX];
lli b[MAX];
map<lli,set<lli> > fnt;
map<lli ,set<lli> > bck;
map<lli ,set<lli> > same;
bool check(lli x)
{
    lli res=LONG_MAX;
    for(int i=0;i<n;i++)
    {
        lli color=f[i];
       // cout<<"color :"<<color<<"\n";
        lli d=limit-fnt[color].size();
        //cout<<"remain :"<<d<<"\n";
        if(d<=0)
        {
            return true;
        }
        lli av=bck[color].size()-same[color].size();
        //cout<<"avilable :"<<av<<"\n";
        if(av>=d)
        {
            if(x>=d)
            {
               return true;
            }
        }

    }
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   //lli tc;
   // cin>>tc;
    factorial(200005,mod);
    InverseofNumber(200005,mod);
    InverseofFactorial(200005,mod);
    //while(tc--)
    //{

        cin>>n;
        limit=(n+1)/2;
        for(int i=0;i<n;i++)
        {
            cin>>f[i]>>b[i];
            fnt[f[i]].insert(i);
            bck[b[i]].insert(i);
            if(f[i]==b[i])
            {
                same[f[i]].insert(i);
            }
        }
        lli l=0;
        lli r=n;
        lli ans=LONG_MAX;
        while(l<=r)
        {
            lli mid=(l+r)/2;
           // cout<<l<<" "<<r<<" "<<mid<<"\n";
            if(check(mid))
            {
                ans=min(ans,mid);
                r=mid-1;
            }
            else
            {
                l=mid+1;
            }
        }
        cout<<ans<<"\n";

    //}
    return 0;
}


#include <cstdio>
#include <iostream>
#include <map>

#define oo 2000000000

using namespace std;

map<long,long> hash;

struct case1
{
 long a,b;
}cards[200005]={0};

int main()
{
 long n,i,j;
 long ans=oo;

 scanf("%ld",&n);
 for(i=1;i<=n;i++)
   {
    scanf("%ld%ld",&cards[i].a,&cards[i].b);
    hash[cards[i].a]++;
    if(cards[i].a!=cards[i].b)
     hash[cards[i].b]++;
   }

 for(map<long,long>::iterator p=hash.begin();p!=hash.end();p++)
   if(p->second>=(n+1)/2)
    {
     long s=(n+1)/2;
     for(i=1;i<=n;i++)
       s-=cards[i].a==p->first;
     ans=min(ans,max(s,0L));
    }

 if(ans==oo)
  cout<<-1<<endl;
 else
  cout<<ans<<endl;

 return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <stack>
using namespace std;
const int maxn=100001;
#define INF 0x3f3f3f3f
struct COLOR
{
    int cl;
    int cnt;
};
COLOR color1[maxn],color2[maxn],tcl;
map<int,int>mp;
map<int,int>num;
 int main()
{
    int i,j,n,p1=0,p2=0,ans=INF,a,b;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d %d",&(a),&(b));
        if(mp[a]==0)
        {
            tcl.cl=a;
            color1[p1++]=tcl;
        }
        if(num[b]==0&&a!=b)
        {
             tcl.cl=b;
             color2[p2++]=tcl;
        }
        mp[a]++;
        if(a!=b)
            num[b]++;
    }
    for(i=0;i<p1;i++)
        color1[i].cnt=mp[color1[i].cl];
    for(i=0;i<p2;i++)
        color2[i].cnt=num[color2[i].cl];
    for(i=0;i<p1;i++)
    {
        int cl=color1[i].cl;
        int cnt=color1[i].cnt;
        double mid=1.0*n/2;
        int t=(int)mid;
        if(mid>t)
           t++;
        if(cnt>=t)
             ans=min(ans,0);
        else
        {
             if(cnt+num[cl]>=t)
                 ans=min(ans,t-cnt);
        }
    }
    for(i=0;i<p2;i++)
    {
         int cl=color2[i].cl;
         int cnt=color2[i].cnt;
         double mid=1.0*n/2;
         int t=(int)mid;
         if(mid>t)
             t++;
         if(mp[cl]>t)
            continue;
         if(cnt+mp[cl]>=t)
             ans=min(ans,t-mp[cl]);
    }
    if(ans==INF)
       printf("-1\n");
    else
       printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#define INF 0x3f3f3f3f
#define ll long long
const ll maxn=1e5+5;
const ll maxm=1e8;
using namespace std;
struct node
{
    ll a;
    ll b;
} s[maxn];
ll m[maxm];
bool cmp(struct node a,struct node b)
{
    if(a.a==b.a)
        return a.b<b.b;
    return a.a<b.a;
}
int main()
{
    ll n,i,num=0,cz=0,kmax,pmax;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld %lld",&s[i].a,&s[i].b);
        if(s[i].a==s[i].b)
            m[s[i].a]++;
        else
        {
            m[s[i].a]++;
            m[s[i].b]++;
        }
    }
    kmax=m[0];
    pmax=0;
    for(i=1;i<2*n;i++)
    {
        if(m[i]>kmax)
        {
            kmax=m[i];
            pmax=i;
        }
    }
    sort(s,s+n,cmp);
    for(i=0; i<n; i++)
    {
        if(s[i].a==pmax)
        {
            num++;
        }
        if(s[i].a!=pmax&&s[i].b==pmax)
        {
            num++;
            cz++;
        }
        if(num>=(n+1)/2)
            break;
    }
    printf("%lld\n",cz);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <stack>
using namespace std;
const int maxn=100001;
struct node
{
    int a,b;
};
struct COLOR
{
    int cl;
    int cnt;
};
COLOR color[maxn],tcl;
map<int,int>mp;
node a[maxn];
bool cmp(COLOR a,COLOR b)
{
    return a.cnt>b.cnt;
}
int main()
{
    int i,j,n,p=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d %d",&(a[i].a),&(a[i].b));
        if(mp[a[i].a]==0)
        {
            tcl.cl=a[i].a;
            color[p++]=tcl;
        }
        mp[a[i].a]++;
    }
    for(i=0;i<p;i++)
        color[i].cnt=mp[color[i].cl];
    sort(color,color+p,cmp);
    for(i=0;i<p;i++)
    {
        int cl=color[i].cl;
        int cnt=color[i].cnt;
        if((double)color[i].cnt>=(double)n/2)
        {
            printf("0\n");
            return 0;
        }
        for(j=1;j<=n;j++)
        {
            if(a[j].b==cl&&a[j].a!=cl)
            {
                  cnt++;
                  if((double)cnt>=(double)n/2)
                  {
                      printf("%d\n",cnt-color[i].cnt);
                      return 0;
                  }
            }
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>

#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#define mem(a) memset(a,0,sizeof(a))
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
const long long maxn=1e5+5;
const int inf=0x3f3f3f3f;
struct node
{
    int a;
    int b;
} t[maxn];
map<char,int> show;
int coun[1000005];
int main()
{
    int n,m,i,j=0,k,l,sum=0,minn=inf,p,ans;
    bool flag=false;
    scanf("%d",&n);
    p=(n+1)/2;
    for(i=0; i<n; i++)
    {
        scanf("%d %d",&t[i].a,&t[i].b);
        if(t[i].a==t[i].b)
        {
            show[t[i].a+48]++;
        }
        else
        {
            show[t[i].a+48]++;
            show[t[i].b+48]++;
        }
        if(show[t[i].a+48]==p)
        {
            flag=true;
            coun[j++]=t[i].a;
        }
        if(show[t[i].b+48]==p)
        {
            flag=true;
            coun[j++]=t[i].b;
        }
    }
    if(flag==false)
    {
        printf("-1\n");
        return 0;
    }
    for(i=0; i<j; i++)
    {
        sum=0;
        for(k=0;k<n;k++)
        {
            if(t[k].a==coun[i])
            {
                sum++;
            }
        }
        ans=p-sum;
        if(ans<=0)
        {
            printf("0\n");
            return 0;
        }
        else
        {
            if(ans<minn)
                minn=ans;
        }
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <stack>
using namespace std;
const int maxn=100001;
#define INF 0x3f3f3f3f
struct COLOR
{
    int cl;
    int cnt;
};
COLOR color1[maxn],color2[maxn],tcl;
map<int,int>mp;
map<int,int>num;
bool cmp(COLOR a,COLOR b)
{
    return a.cnt>b.cnt;
}
int main()
{
    int i,j,n,p1=0,p2=0,ans=INF,a,b;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d %d",&(a),&(b));
        if(mp[a]==0)
        {
            tcl.cl=a;
            color1[p1++]=tcl;
        }
        if(num[b]==0&&a!=b)
        {
             tcl.cl=b;
             color2[p2++]=tcl;
        }
        mp[a]++;
        if(a!=b)
            num[b]++;
    }
    for(i=0;i<p1;i++)
        color1[i].cnt=mp[color1[i].cl];
    for(i=0;i<p2;i++)
        color2[i].cnt=num[color2[i].cl];
    for(i=0;i<p1;i++)
    {
        int cl=color1[i].cl;
        int cnt=color1[i].cnt;
        double mid=1.0*n/2;
        int t=(int)mid;
        if(mid>t)
           t++;
        if(cnt>=t)
             ans=min(ans,0);
        else
        {
             if(cnt+num[cl]>=t)
                 ans=min(ans,t-cnt);
        }
    }
    for(i=0;i<p2;i++)
    {
         int cl=color2[i].cl;
         int cnt=color2[i].cnt;
         double mid=1.0*n/2;
         int t=(int)mid;
         if(mid>t)
             t++;
         if(cnt+mp[cl]>=t)
             ans=min(ans,t-mp[cl]);
    }
    if(ans==INF)
       printf("-1\n");
    else
       printf("%d\n",ans);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#define INF 0x3f3f3f3f
#define ll long long
const ll maxn=1e5+5;
using namespace std;
struct node
{
    ll a;
    ll b;
} s[maxn];
bool cmp(struct node a,struct node b)
{
    if(a.a==b.a)
        return a.b<b.b;
    return a.a<b.a;
}
int main()
{
    ll n,i,num=1,cz=0;
    scanf("%lld",&n);
    for(i=0; i<n; i++)
    {
        scanf("%lld %lld",&s[i].a,&s[i].b);
    }
    sort(s,s+n,cmp);
    for(i=0; i<n-1; i++)
    {
        if((s[i].a==s[i+1].a)||(s[i].b==s[i+1].b))
        {
            num++;
        }
        else if((s[i].a==s[i+1].b)||(s[i].b==s[i+1].a))
        {
            cz++;
            num++;
        }
        if(num>=(n+1)/2)
            break;
    }
    printf("%lld\n",cz);
    return 0;
}


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

		using namespace std;
		using namespace __gnu_pbds;
		#define  lld long long int

		typedef pair< lld, lld > pii;
						typedef map<lld,lld> mii;
						typedef map<char,lld>sii;
						typedef pair<lld,lld>pii;
						typedef vector<lld>vi;
						typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

						#define pb push_back
						#define tr(it,ct) for(auto &(it) : ct)
						#define  F first
						#define  S second
						#define clr(a,b) memset((a), (b), sizeof(a))

						#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
						#define all(c) (c).begin(),(c).end()

						#define ref 1e9+7
						#define  mp make_pair
		 				#define ook order_of_key

			void swap(char &a,char &b)
			{ auto tm=a; a=b; b=tm; }
			lld power(lld  x, lld y, lld p)
		{
		    lld  res = 1;      // Initialize result

		    x = x % p;  // Update x if it is more than or
		                // equal to p

		    while (y > 0)
		    {
		        // If y is odd, multiply x with result
		        if (y & 1)
		            res = (res*x) % p;

		        // y must be even now
		        y = y>>1; // y = y/2
		        x = (x*x) % p;
		    }
		    return res;
		}

		// Returns n^(-1) mod p
		lld modInverse(lld n, lld p)
		{
		    return power(n, p-2, p);
		}
		bool comparator1(const pair<int , int> &a , const pair<int , int> &b) { return a.first < b.first; }

		// Returns nCr % p using Fermat's little
		// theorem.
		lld nCrModPFermat(lld n, lld r, lld p)
		{
		   // Base case
		   if (r==0)
		      return 1;

		    // Fill factorial array so that we
		    // can find all factorial of r, n
		    // and n-r
		    lld fac[n+1];
		    fac[0] = 1;
		    for (lld i=1 ; i<=n; i++)
		        fac[i] = fac[i-1]*i%p;

		    return (fac[n]* modInverse(fac[r], p) % p *
		            modInverse(fac[n-r], p) % p) % p;
		}

	void jai_mata_di()
	{
		lld q;
		q=1;
		while(q--)
		{
			lld n,i,j,k;string t;
		cin>>n;
		vector<pii>v(n);mii f,b;lld ans=1e13;
		for(i=0;i<n;i++)cin>>v[i].F>>v[i].S,f[v[i].F]++,b[v[i].S]++;
			lld mn=1e13;lld x = n/2;if(n%2)x++;//cout<<x;
		for(i=0;i<n;i++)
		{
			if((f[v[i].F]+b[v[i].F])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].F]);
				ans = min(g,ans);
			}
		}
		for(i=0;i<n;i++)
		{
			if((f[v[i].S]+b[v[i].S])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].S]);
				ans = min(g,ans);
			}
		}
		cout<<ans;

		}

						}

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

						  lld tt=1.0*clock();
						   #ifndef ONLINE_JUDGE

						   freopen("input.txt", "r", stdin);

						   freopen("output.txt", "w", stdout);

						   freopen("error.txt","w", stderr);
						   #endif

						  int t;

				//	cin>>t;

					t=1;

						for(int y=0;y<t;y++)
						  { // cout<<"Scenario #"<<i<<":\n";
						   jai_mata_di();
						 cout<<endl;

						 return 0;
						}
					}


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

		using namespace std;
		using namespace __gnu_pbds;
		#define  lld long long int

		typedef pair< lld, lld > pii;
						typedef map<lld,lld> mii;
						typedef map<char,lld>sii;
						typedef pair<lld,lld>pii;
						typedef vector<lld>vi;
						typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

						#define pb push_back
						#define tr(it,ct) for(auto &(it) : ct)
						#define  F first
						#define  S second
						#define clr(a,b) memset((a), (b), sizeof(a))

						#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
						#define all(c) (c).begin(),(c).end()

						#define ref 1e9+7
						#define  mp make_pair
		 				#define ook order_of_key

			void swap(char &a,char &b)
			{ auto tm=a; a=b; b=tm; }
			lld power(lld  x, lld y, lld p)
		{
		    lld  res = 1;      // Initialize result

		    x = x % p;  // Update x if it is more than or
		                // equal to p

		    while (y > 0)
		    {
		        // If y is odd, multiply x with result
		        if (y & 1)
		            res = (res*x) % p;

		        // y must be even now
		        y = y>>1; // y = y/2
		        x = (x*x) % p;
		    }
		    return res;
		}

		// Returns n^(-1) mod p
		lld modInverse(lld n, lld p)
		{
		    return power(n, p-2, p);
		}
		bool comparator1(const pair<int , int> &a , const pair<int , int> &b) { return a.first < b.first; }

		// Returns nCr % p using Fermat's little
		// theorem.
		lld nCrModPFermat(lld n, lld r, lld p)
		{
		   // Base case
		   if (r==0)
		      return 1;

		    // Fill factorial array so that we
		    // can find all factorial of r, n
		    // and n-r
		    lld fac[n+1];
		    fac[0] = 1;
		    for (lld i=1 ; i<=n; i++)
		        fac[i] = fac[i-1]*i%p;

		    return (fac[n]* modInverse(fac[r], p) % p *
		            modInverse(fac[n-r], p) % p) % p;
		}

	void jai_mata_di()
	{
		lld q;
		q=1;
		while(q--)
		{
			lld n,i,j,k;string t;
		cin>>n;
		vector<pii>v(n);mii f,b,c;lld ans=1e13;
		for(i=0;i<n;i++){cin>>v[i].F>>v[i].S,f[v[i].F]++,b[v[i].S]++;if(v[i].F==v[i].S)c[v[i].F]++;}
			lld mn=1e13;lld x = n/2;if(n%2)x++;
		for(i=0;i<n;i++)
		{
			if((f[v[i].F]+b[v[i].F]-c[v[i].F])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].F]);
				ans = min(g,ans);
			}
		}
		for(i=0;i<n;i++)
		{
			if((f[v[i].S]+b[v[i].S]-c[v[i].S])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].S]);
				ans = min(g,ans);
			}
		}
	if(ans!=1e13)	cout<<ans;
	else cout<<-1;

		}

						}

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

						  lld tt=1.0*clock();
						   #ifndef ONLINE_JUDGE

						   freopen("input.txt", "r", stdin);

						   freopen("output.txt", "w", stdout);

						   freopen("error.txt","w", stderr);
						   #endif

						  int t;

				//	cin>>t;

					t=1;

						for(int y=0;y<t;y++)
						  { // cout<<"Scenario #"<<i<<":\n";
						   jai_mata_di();
						 cout<<endl;

						 return 0;
						}
					}


		#include<bits/stdc++.h>
			using namespace std;
			#define pb push_back
			#define tr(it,ct) for(auto &(it) : ct)
			#define  F first
			#define  S second
			#define clr(a,b) memset((a), (b), sizeof(a))
			#define  lld long long int
			#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
			#define all(c) (c).begin(),(c).end()
			typedef pair< lld, lld > pii;
			typedef map<lld,lld> mii;
			typedef map<char,lld>sii;
			typedef vector<lld>vi;
			#define ref 1000000007
			#define  mp make_pair
		lld sum=0;
		lld par[150005];
	lld find(lld x)

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

	}
void jai_mata_di()
{ lld q;
q=1;
while(q--){lld n,k,i,j,c=0;
cin>>n;mii f,b;vector<pair<lld,lld>>v(n);
for(i=0;i<n;i++)
{
	cin>>v[i].F>>v[i].S;
	if(v[i].F!=v[i].S)
	{
		f[v[i].F]++;b[v[i].S]++;
	}
	else
	{
		f[v[i].F]++;
	}
}if(n%2)j=(n/2)+1;else j=n/2;lld ans=1e13;//cout<<j<<endl;
for(i=0;i<n;i++)
{
	if(f[v[i].F]>=j){ans=0;break;}
	else
	{
		if(f[v[i].F]+b[v[i].F]>=j){ans=min(ans,max(c,j-f[v[i].F]));}
	}

}
for(i=0;i<n;i++)
{

		if(f[v[i].S]+b[v[i].S]>=j)ans=min(ans,max(c,j-f[v[i].S]));//cout<<ans<<" ";}

}
if(ans!=1e13)cout<<ans;
else cout<<-1;

}

}

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

			  lld tt=1.0*clock();
			   #ifndef ONLINE_JUDGE

			   freopen("input.txt", "r", stdin);

			   freopen("output.txt", "w", stdout);

			   freopen("error.txt","w", stderr);
			   #endif

			  int t;

	//	cin>>t;

		t=1;

			for(int y=0;y<t;y++)
			  { // cout<<"Scenario #"<<i<<":\n";
			   jai_mata_di();
			 cout<<endl;

			 return 0;
			}
		}


		#include<bits/stdc++.h>
			using namespace std;
			#define pb push_back
			#define tr(it,ct) for(auto &(it) : ct)
			#define  F first
			#define  S second
			#define clr(a,b) memset((a), (b), sizeof(a))
			#define  lld long long int
			#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
			#define all(c) (c).begin(),(c).end()
			typedef pair< lld, lld > pii;
			typedef map<lld,lld> mii;
			typedef map<char,lld>sii;
			typedef vector<lld>vi;
			#define ref 1000000007
			#define  mp make_pair
		lld sum=0;
		lld par[150005];
	lld find(lld x)

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

	}
void jai_mata_di()
{ lld q;
q=1;
while(q--){lld n,k,i,j;
cin>>n;mii f,b;vector<pair<lld,lld>>v(n);
for(i=0;i<n;i++)
{
	cin>>v[i].F>>v[i].S;
	if(v[i].F!=v[i].S)
	{
		f[v[i].F]++;b[v[i].S]++;
	}
	else
	{
		f[v[i].F]++;
	}
}if(n%2)j=(n/2)+1;else j=n/2;lld ans=1e13;
for(i=0;i<n;i++)
{
	if(f[v[i].F]>=j){ans=0;break;}
	else
	{
		if(f[v[i].F]+b[v[i].S]>=j)ans=min(ans,j-f[v[i].F]);
	}

}
if(ans!=1e13)cout<<ans;
else cout<<-1;
}

}

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

			  lld tt=1.0*clock();
			   #ifndef ONLINE_JUDGE

			   freopen("input.txt", "r", stdin);

			   freopen("output.txt", "w", stdout);

			   freopen("error.txt","w", stderr);
			   #endif

			  int t;

	//	cin>>t;

		t=1;

			for(int y=0;y<t;y++)
			  { // cout<<"Scenario #"<<i<<":\n";
			   jai_mata_di();
			 cout<<endl;

			 return 0;
			}
		}


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

		using namespace std;
		using namespace __gnu_pbds;
		#define  lld long long int

		typedef pair< lld, lld > pii;
						typedef map<lld,lld> mii;
						typedef map<char,lld>sii;
						typedef pair<lld,lld>pii;
						typedef vector<lld>vi;
						typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

						#define pb push_back
						#define tr(it,ct) for(auto &(it) : ct)
						#define  F first
						#define  S second
						#define clr(a,b) memset((a), (b), sizeof(a))

						#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
						#define all(c) (c).begin(),(c).end()

						#define ref 1e9+7
						#define  mp make_pair
		 				#define ook order_of_key

			void swap(char &a,char &b)
			{ auto tm=a; a=b; b=tm; }
			lld power(lld  x, lld y, lld p)
		{
		    lld  res = 1;      // Initialize result

		    x = x % p;  // Update x if it is more than or
		                // equal to p

		    while (y > 0)
		    {
		        // If y is odd, multiply x with result
		        if (y & 1)
		            res = (res*x) % p;

		        // y must be even now
		        y = y>>1; // y = y/2
		        x = (x*x) % p;
		    }
		    return res;
		}

		// Returns n^(-1) mod p
		lld modInverse(lld n, lld p)
		{
		    return power(n, p-2, p);
		}
		bool comparator1(const pair<int , int> &a , const pair<int , int> &b) { return a.first < b.first; }

		// Returns nCr % p using Fermat's little
		// theorem.
		lld nCrModPFermat(lld n, lld r, lld p)
		{
		   // Base case
		   if (r==0)
		      return 1;

		    // Fill factorial array so that we
		    // can find all factorial of r, n
		    // and n-r
		    lld fac[n+1];
		    fac[0] = 1;
		    for (lld i=1 ; i<=n; i++)
		        fac[i] = fac[i-1]*i%p;

		    return (fac[n]* modInverse(fac[r], p) % p *
		            modInverse(fac[n-r], p) % p) % p;
		}

	void jai_mata_di()
	{
		lld q;
		q=1;
		while(q--)
		{
			lld n,i,j,k;string t;
		cin>>n;
		vector<pii>v(n);mii f,b;lld ans=1e13;
		for(i=0;i<n;i++)cin>>v[i].F>>v[i].S,f[v[i].F]++,b[v[i].S]++;
			lld mn=1e13;lld x = n/2;if(n%2)x++;//cout<<x;
		for(i=0;i<n;i++)
		{
			if((f[v[i].F]+b[v[i].F])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].F]);
				ans = min(g,ans);
			}
		}
		for(i=0;i<n;i++)
		{
			if((f[v[i].S]+b[v[i].S])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].S]);
				ans = min(g,ans);
			}
		}
	if(ans!=1e13)	cout<<ans;
	else cout<<-1;

		}

						}

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

						  lld tt=1.0*clock();
						   #ifndef ONLINE_JUDGE

						   freopen("input.txt", "r", stdin);

						   freopen("output.txt", "w", stdout);

						   freopen("error.txt","w", stderr);
						   #endif

						  int t;

				//	cin>>t;

					t=1;

						for(int y=0;y<t;y++)
						  { // cout<<"Scenario #"<<i<<":\n";
						   jai_mata_di();
						 cout<<endl;

						 return 0;
						}
					}


		#include<bits/stdc++.h>
			using namespace std;
			#define pb push_back
			#define tr(it,ct) for(auto &(it) : ct)
			#define  F first
			#define  S second
			#define clr(a,b) memset((a), (b), sizeof(a))
			#define  lld long long int
			#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
			#define all(c) (c).begin(),(c).end()
			typedef pair< lld, lld > pii;
			typedef map<lld,lld> mii;
			typedef map<char,lld>sii;
			typedef vector<lld>vi;
			#define ref 1000000007
			#define  mp make_pair
		lld sum=0;
		lld par[150005];
	lld find(lld x)

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

	}
void jai_mata_di()
{ lld q;
q=1;
while(q--){lld n,k,i,j;
cin>>n;mii f,b;vector<pair<lld,lld>>v(n);
for(i=0;i<n;i++)
{
	cin>>v[i].F>>v[i].S;
	if(v[i].F!=v[i].S)
	{
		f[v[i].F]++;b[v[i].S]++;
	}
	else
	{
		f[v[i].F]++;
	}
}if(n%2)j=(n/2)+1;else j=n/2;lld ans=1e13;//cout<<j<<endl;
for(i=0;i<n;i++)
{
	if(f[v[i].F]>=j){ans=0;break;}
	else
	{
		if(f[v[i].F]+b[v[i].F]>=j){ans=min(ans,j-f[v[i].F]);}
	}

}
if(ans!=1e13)cout<<ans;
else cout<<-1;
}

}

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

			  lld tt=1.0*clock();
			   #ifndef ONLINE_JUDGE

			   freopen("input.txt", "r", stdin);

			   freopen("output.txt", "w", stdout);

			   freopen("error.txt","w", stderr);
			   #endif

			  int t;

	//	cin>>t;

		t=1;

			for(int y=0;y<t;y++)
			  { // cout<<"Scenario #"<<i<<":\n";
			   jai_mata_di();
			 cout<<endl;

			 return 0;
			}
		}


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

		using namespace std;
		using namespace __gnu_pbds;
		#define  lld long long int

		typedef pair< lld, lld > pii;
						typedef map<lld,lld> mii;
						typedef map<char,lld>sii;
						typedef pair<lld,lld>pii;
						typedef vector<lld>vi;
						typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

						#define pb push_back
						#define tr(it,ct) for(auto &(it) : ct)
						#define  F first
						#define  S second
						#define clr(a,b) memset((a), (b), sizeof(a))

						#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
						#define all(c) (c).begin(),(c).end()

						#define ref 1e9+7
						#define  mp make_pair
		 				#define ook order_of_key

			void swap(char &a,char &b)
			{ auto tm=a; a=b; b=tm; }
			lld power(lld  x, lld y, lld p)
		{
		    lld  res = 1;      // Initialize result

		    x = x % p;  // Update x if it is more than or
		                // equal to p

		    while (y > 0)
		    {
		        // If y is odd, multiply x with result
		        if (y & 1)
		            res = (res*x) % p;

		        // y must be even now
		        y = y>>1; // y = y/2
		        x = (x*x) % p;
		    }
		    return res;
		}

		// Returns n^(-1) mod p
		lld modInverse(lld n, lld p)
		{
		    return power(n, p-2, p);
		}
		bool comparator1(const pair<int , int> &a , const pair<int , int> &b) { return a.first < b.first; }

		// Returns nCr % p using Fermat's little
		// theorem.
		lld nCrModPFermat(lld n, lld r, lld p)
		{
		   // Base case
		   if (r==0)
		      return 1;

		    // Fill factorial array so that we
		    // can find all factorial of r, n
		    // and n-r
		    lld fac[n+1];
		    fac[0] = 1;
		    for (lld i=1 ; i<=n; i++)
		        fac[i] = fac[i-1]*i%p;

		    return (fac[n]* modInverse(fac[r], p) % p *
		            modInverse(fac[n-r], p) % p) % p;
		}

	void jai_mata_di()
	{
		lld q;
		q=1;
		while(q--)
		{
			lld n,i,j,k;string t;
		cin>>n;
		vector<pii>v(n);mii f,b;lld ans=1e13;
		for(i=0;i<n;i++)cin>>v[i].F>>v[i].S,f[v[i].F]++,b[v[i].S]++;
			lld mn=1e13;lld x = n/2;//cout<<x;
		for(i=0;i<n;i++)
		{
			if((f[v[i].F]+b[v[i].F])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].F]);
				ans = min(g,ans);
			}
		}
		for(i=0;i<n;i++)
		{
			if((f[v[i].S]+b[v[i].S])>=x)
			{
				lld g  = max((lld)0,x-f[v[i].S]);
				ans = min(g,ans);
			}
		}
	if(ans!=1e13)	cout<<ans;
	else cout<<-1;

		}

						}

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

						  lld tt=1.0*clock();
						   #ifndef ONLINE_JUDGE

						   freopen("input.txt", "r", stdin);

						   freopen("output.txt", "w", stdout);

						   freopen("error.txt","w", stderr);
						   #endif

						  int t;

				//	cin>>t;

					t=1;

						for(int y=0;y<t;y++)
						  { // cout<<"Scenario #"<<i<<":\n";
						   jai_mata_di();
						 cout<<endl;

						 return 0;
						}
					}


		#include<bits/stdc++.h>
			using namespace std;
			#define pb push_back
			#define tr(it,ct) for(auto &(it) : ct)
			#define  F first
			#define  S second
			#define clr(a,b) memset((a), (b), sizeof(a))
			#define  lld long long int
			#define optimize()   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
			#define all(c) (c).begin(),(c).end()
			typedef pair< lld, lld > pii;
			typedef map<lld,lld> mii;
			typedef map<char,lld>sii;
			typedef vector<lld>vi;
			#define ref 1000000007
			#define  mp make_pair
		lld sum=0;
		lld par[150005];
	lld find(lld x)

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

	}
void jai_mata_di()
{ lld q;
q=1;
while(q--){lld n,k,i,j;
cin>>n;mii f,b;vector<pair<lld,lld>>v(n);
for(i=0;i<n;i++)
{
	cin>>v[i].F>>v[i].S;
	if(v[i].F!=v[i].S)
	{
		f[v[i].F]++;b[v[i].S]++;
	}
	else
	{
		f[v[i].F]++;
	}
}if(n%2)j=(n/2)+1;else j=n/2;lld ans=1e13;//cout<<j<<endl;
for(i=0;i<n;i++)
{
	if(f[v[i].F]>=j){ans=0;break;}
	else
	{
		if(f[v[i].F]+b[v[i].F]>=j){ans=min(ans,j-f[v[i].F]);}
	}

}
for(i=0;i<n;i++)
{

		if(f[v[i].S]+b[v[i].S]>=j){ans=min(ans,j-f[v[i].S]);}

}
if(ans!=1e13)cout<<ans;
else cout<<-1;
}

}

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

			  lld tt=1.0*clock();
			   #ifndef ONLINE_JUDGE

			   freopen("input.txt", "r", stdin);

			   freopen("output.txt", "w", stdout);

			   freopen("error.txt","w", stderr);
			   #endif

			  int t;

	//	cin>>t;

		t=1;

			for(int y=0;y<t;y++)
			  { // cout<<"Scenario #"<<i<<":\n";
			   jai_mata_di();
			 cout<<endl;

			 return 0;
			}
		}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[200200][2],n,k;
map<int,int> mp;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k;
			k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k;
			k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<200200 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		else
			ans = min(ans , (n+1/2)-a[i][0]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[200200][2],n,k;
map<int,int> mp;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k;
			k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k;
			k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
		if(x==y){
			a[mp[y]][1]--;
		}
	}
	int ans = 1000000000;
	for(int i=0 ; i<200200 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		else
			ans = min(ans , (n+1)/2 - a[i][0]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[200200][2],n,k;
map<int,int> mp;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k;
			k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k;
			k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<200200 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		ans = min(ans , (n+1/2)-a[i][0]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[200200][2],n,k;
map<int,int> mp;
vint v;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<200200 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		ans = min(ans , a[i][1]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[200200][2],n,k;
map<int,int> mp;
vint v;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<100100 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		ans = min(ans , a[i][1]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[100100][2],n,k;
map<int,int> mp;
vint v;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<100100 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		ans = min(ans , a[i][1]);
	}
	cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[200200][2],n,k;
map<int,int> mp;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k;
			k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k;
			k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<200200 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		else
			ans = min(ans , (n+1)/2 - a[i][0]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


/* In The Name Of God */
#include <bits/stdc++.h>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
int a[100100][2],n,k;
map<int,int> mp;
vint v;
int main(){
	ios_base::sync_with_stdio (0);
	cin>>n;
	for(int i=0 ; i<n ; i++){
		int x,y;cin>>x>>y;
		if(mp.find(x) == mp.end()){
			mp[x] = k++;
		}
		if(mp.find(y) == mp.end()){
			mp[y] = k++;
		}
		a[mp[x]][0]++;
		a[mp[y]][1]++;
	}
	int ans = 1000000000;
	for(int i=0 ; i<100100 ; i++)if(a[i][0] + a[i][1] >= (n+1)/2){
		if(a[i][0] >= (n+1)/2)
			ans = 0;
		ans = min(ans , a[i][1]);
	}
	if(ans > 1e8)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	unordered_set<int> st;
	unordered_map<int, int> aa, bb;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		aa[a]++;
		if (a != b) bb[b]++;
		st.insert(a);
		st.insert(b);
	}
	for (auto i: st) {
		if (aa[i] >= n/2) {
			cout << "0\n";
			return 0;
		} else if (aa[i] + bb[i] >= n/2+n%2) {
			cout << n/2+n%2 - aa[i] << '\n';
			return 0;
		}
	}
	cout << "-1\n";
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	unordered_set<int> st;
	unordered_map<int, int> aa, bb;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		aa[a]++;
		if (a != b) bb[b]++;
		st.insert(a);
		st.insert(b);
	}
	for (auto i: st) {
		if (aa[i] >= n/2+n%2) {
			cout << "0\n";
			return 0;
		} else if (aa[i] + bb[i] >= n/2+n%2) {
			cout << n/2+n%2 - aa[i] << '\n';
			return 0;
		}
	}
	cout << "-1\n";
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	unordered_set<int> st;
	unordered_map<int, int> aa, bb;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		aa[a]++;
		if (a != b) bb[b]++;
		st.insert(a);
		st.insert(b);
	}
	int ans = 1e9;
	for (auto i: st) {
		if (aa[i] >= n/2+n%2) {
			ans = 0;
		} else if (aa[i] + bb[i] >= n/2+n%2) {
			ans = min(ans, n/2+n%2 - aa[i]);
		}
	}
	if (ans == 1e9) cout << "-1\n";
	else cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	unordered_set<int> st;
	unordered_map<int, int> aa, bb;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		aa[a]++;
		if (a != b) bb[b]++;
		st.insert(a);
		st.insert(b);
	}
	int ans = 1e9;
	for (auto i: st) {
		if (aa[i] >= n/2+n%2) {
			ans = 0;
		} else if (aa[i] + bb[i] >= n/2+n%2) {
			ans = min(ans, n/2+n%2 - aa[i]);
		}
	}
	if (ans == 1e9) cout << "-1\n";
	else cout << ans << '\n';
}


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

struct card{
	ll front,back;
};

card a[100001];

map<ll,ll> demf;

map<ll,ll> demb;

bool card_comp(card a,card b){
	return a.front<b.front||(a.front==b.front&&a.back<b.back);
}

int main(){
	ll n,kq=1e18;
	cin>>n;
	ll same=(n+1)/2;
	for(ll i=1;i<=n;i++){
		cin>>a[i].front>>a[i].back;
		if(a[i].front!=a[i].back){
			demf[a[i].front]++;
			demb[a[i].back]++;
		}
		else demf[a[i].front]++;
	}
	sort(a+1,a+1+n,card_comp);
	for(ll i=1;i<=n;i++){
		if(a[i].front!=a[i-1].front)
			if(demf[a[i].front]+demb[a[i].front]>=same) kq=min(kq,max((ll)0,same-demf[a[i].front]));
	}
	cout<<(kq!=1e18?kq:-1);
}


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

struct card{
	ll front,back;
};

card a[100001];

map<ll,ll> demf;

map<ll,ll> demb;

bool card_comp(card a,card b){
	return a.front<b.front||(a.front==b.front&&a.back<b.back);
}

int main(){
	ll n,kq=1e18;
	cin>>n;
	ll same=(n+1)/2;
	for(ll i=1;i<=n;i++){
		cin>>a[i].front>>a[i].back;
		demf[a[i].front]++;
		demb[a[i].back]++;
	}
	sort(a+1,a+1+n,card_comp);
	for(ll i=1;i<=n;i++){
		if(a[i].front!=a[i-1].front)
			if(demf[a[i].front]+demb[a[i].front]>=same) kq=min(kq,max((ll)0,same-demf[a[i].front]));
	}
	cout<<(kq!=1e18?kq:-1);
}


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

struct card{
	ll front,back;
};

card a[100001];

map<ll,ll> demf;

map<ll,ll> demb;

bool card_comp1(card a,card b){
	return a.front<b.front||(a.front==b.front&&a.back<b.back);
}

bool card_comp2(card a,card b){
	return a.back<b.back||(a.back==b.back&&a.front<b.front);
}

int main(){
	ll n,kq=1e18;
	cin>>n;
	ll same=(n+1)/2;
	for(ll i=1;i<=n;i++){
		cin>>a[i].front>>a[i].back;
		if(a[i].front!=a[i].back){
			demf[a[i].front]++;
			demb[a[i].back]++;
		}
		else demf[a[i].front]++;
	}
	sort(a+1,a+1+n,card_comp1);
	for(ll i=1;i<=n;i++){
		if(a[i].front!=a[i-1].front)
			if(demf[a[i].front]+demb[a[i].front]>=same) kq=min(kq,max((ll)0,same-demf[a[i].front]));
	}
	sort(a+1,a+1+n,card_comp2);
	for(ll i=1;i<=n;i++){
		if(a[i].back!=a[i-1].back)
			if(demf[a[i].back]+demb[a[i].back]>=same) kq=min(kq,max((ll)0,same-demf[a[i].back]));
	}
	cout<<(kq!=1e18?kq:-1);
}


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

struct card{
	ll front,back;
};

card a[100001];

map<ll,ll> demf;

map<ll,ll> demb;

bool card_comp(card a,card b){
	return a.front<b.front||(a.front==b.front&&a.back<b.back);
}

int main(){
	ll n,kq=1e18;
	cin>>n;
	ll same=(n+1)/2;
	for(ll i=1;i<=n;i++){
		cin>>a[i].front>>a[i].back;
		demf[a[i].front]++;
		demb[a[i].back]++;
	}
	sort(a+1,a+1+n,card_comp);
	for(ll i=1;i<=n;i++){
		if(a[i].front!=a[i-1].front)
			if(demf[a[i].front]+demb[a[i].front]>=same) kq=min(kq,same-demf[a[i].front]);
	}
	cout<<(kq!=1e18?kq:-1);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#define INF 0x3f3f3f3f
#define ll long long
const ll maxn=1e5+5;
using namespace std;
struct node
{
    ll a;
    ll b;
} ;
map<int,node>m;
int s[maxn];
/*bool cmp(struct node a,struct node b)
{
    if(a.a==b.a)
        return a.b<b.b;
    return a.a<b.a;
}*/
int main()
{
    ll n,i,cz=-1,k=0,l,r,t;
    scanf("%lld",&n);
    t=(n+1)/2;
    for(i=0; i<n; i++)
    {
        scanf("%lld %lld",&l,&r);
        if(l!=r)
        {
            m[l].a++;
            m[r].b++;
            s[k++]=l;
            s[k++]=r;
        }
        else
        {
            m[l].a++;
            s[k++]=l;
        }
    }
    for(i=0; i<k; i++)
    {
        if(m[s[i]].a+m[s[i]].b>=t)
        {
            if(m[s[i]].a>=t)
            {
                printf("0\n");
                return 0;
            }
            else
            {
                if(cz==-1)
                    cz=t-m[s[i]].a;
                else
                    cz=min(cz,t-m[s[i]].a);
            }
        }
    }
    printf("%lld\n",cz);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#define INF 0x3f3f3f3f
#define ll long long
const ll maxn=1e6+5;
using namespace std;
struct node
{
    ll a;
    ll b;
} ;
map<int,node>m;
int s[maxn];
/*bool cmp(struct node a,struct node b)
{
    if(a.a==b.a)
        return a.b<b.b;
    return a.a<b.a;
}*/
int main()
{
    ll n,i,cz=-1,k=0,l,r,t;
    scanf("%lld",&n);
    t=(n+1)/2;
    for(i=0; i<n; i++)
    {
        scanf("%lld %lld",&l,&r);
        if(l!=r)
        {
            m[l].a++;
            m[r].b++;
            s[k++]=l;
            s[k++]=r;
        }
        else
        {
            m[l].a++;
            s[k++]=l;
        }
    }
    for(i=0; i<k; i++)
    {
        if(m[s[i]].a+m[s[i]].b>=t)
        {
            if(m[s[i]].a>=t)
            {
                printf("0\n");
                return 0;
            }
            else
            {
                if(cz==-1)
                    cz=t-m[s[i]].a;
                else
                    cz=min(cz,t-m[s[i]].a);
            }
        }
    }
    printf("%lld\n",cz);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>

#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#define mem(a) memset(a,0,sizeof(a))
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
const long long maxn=1e5+5;
const int inf=0x3f3f3f3f;
struct node
{
    int a;
    int b;
} t[maxn];
map<int,int> show;
int coun[1000005];
int main()
{
    int n,m,i,j=0,k,l,sum=0,minn=inf,p,ans;
    bool flag=false;
    scanf("%d",&n);
    p=(n+1)/2;
    for(i=0; i<n; i++)
    {
        scanf("%d %d",&t[i].a,&t[i].b);
        if(t[i].a==t[i].b)
        {
            show[t[i].a]++;
        }
        else
        {
            show[t[i].a]++;
            show[t[i].b]++;
        }
        if(show[t[i].a]==p)
        {
            flag=true;
            coun[j++]=t[i].a;
        }
        if(show[t[i].b]==p)
        {
            flag=true;
            coun[j++]=t[i].b;
        }
    }
    if(flag==false)
    {
        printf("-1\n");
        return 0;
    }
    for(i=0; i<j; i++)
    {
        sum=0;
        for(k=0;k<n;k++)
        {
            if(t[k].a==coun[i])
            {
                sum++;
            }
        }
        ans=p-sum;
        if(ans<=0)
        {
            printf("0\n");
            return 0;
        }
        else
        {
            if(ans<minn)
                minn=ans;
        }
    }
    printf("%d\n",minn);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>

#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<queue>
#define mem(a) memset(a,0,sizeof(a))
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
const long long maxn=1e2+5;
const int inf=0x3f3f3f3f;
struct node
{
    int a;
    int b;
} t[105];
map<char,int> show;
int coun[maxn];
int main()
{
    int n,m,i,j=0,k,l,sum=0,minn=inf,p,ans;
    bool flag=false;
    scanf("%d",&n);
    p=(n+1)/2;
    for(i=0; i<n; i++)
    {
        scanf("%d %d",&t[i].a,&t[i].b);
        if(t[i].a==t[i].b)
        {
            show[t[i].a+48]++;
        }
        else
        {
            show[t[i].a+48]++;
            show[t[i].b+48]++;
        }
        if(show[t[i].a+48]==p)
        {
            flag=true;
            coun[j++]=t[i].a;
        }
        if(show[t[i].b+48]==p)
        {
            flag=true;
            coun[j++]=t[i].b;
        }
    }
    if(flag==false)
    {
        printf("-1\n");
        return 0;
    }
    for(i=0; i<j; i++)
    {
        sum=0;
        for(k=0;k<n;k++)
        {
            if(t[k].a==coun[i])
            {
                sum++;
            }
        }
        ans=p-sum;
        if(ans<=0)
        {
            printf("0\n");
            return 0;
        }
        else
        {
            if(ans<minn)
                minn=ans;
        }
    }
    printf("%d\n",ans);
}


/* Sachin Chandani
 IIIT Hyderabad  */

#include<bits/stdc++.h>

using namespace std;
#define INF INT_MAX
#define nl '\n'
#define PB push_back
#define SET(a,b) memset(a,b,sizeof(a))
#define fr(a,b,i) for(int i=a;i<=b;i++)
#define rev(a,b,i) for(int i=a;i>=b;i--)
#define fast_scan ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ini(x) scanf("%d",&x)
#define inll(x) scanf("%lld",&x)
#define ins(x) scanf("%s",x)
#define outi(x) printf("%d\n",x)
#define outll(x) printf("%lld\n",x)
#define outs(x) printf("%s\n",x)

const int SIZE=(int)3e5 + 5;

int main()
{
	fast_scan;
	int n;
	int l,r;
	cin>>n;
	int req=(n%2==0?n/2:n/2+1);
	map<int,int> front ,back;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		if(l==r) front[l]++;
		else {front[l]++;back[r]++;}
	}
	std:: map<int ,int> :: iterator it;
	int min=INF;
	for(it=front.begin();it!=front.end();it++)
	{
		if(it->second+back[(int)it->first]>=req)
		{
			if(req-(it->second)>=0 && back[(int)it->first]>=req-(it->second))
			{
				if(req-(it->second)<min)
					min=req-(it->second);
			}
			else if(req-(it->second)>=0 && back[(int)it->first]<req-(it->second)) continue;

		}
	}
	for(it=back.begin();it!=back.end();it++)
	{
		if(it->second+front[(int)it->first]>=req)
		{
			if(req-front[(int)it->first]>=0 && it->second>=req-(front[(int)it->first]))
			{
				if(req-front[(int)it->first]<min)
					min=req-(front[(int )it->first]);
			}
			else continue;
		}
	}
	cout<<min<<nl;
	return 0;
}


/* Sachin Chandani
 IIIT Hyderabad  */

#include<bits/stdc++.h>

using namespace std;
#define INF INT_MAX
#define nl '\n'
#define PB push_back
#define SET(a,b) memset(a,b,sizeof(a))
#define fr(a,b,i) for(int i=a;i<=b;i++)
#define rev(a,b,i) for(int i=a;i>=b;i--)
#define fast_scan ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ini(x) scanf("%d",&x)
#define inll(x) scanf("%lld",&x)
#define ins(x) scanf("%s",x)
#define outi(x) printf("%d\n",x)
#define outll(x) printf("%lld\n",x)
#define outs(x) printf("%s\n",x)

const int SIZE=(int)3e5 + 5;

int main()
{
	fast_scan;
	int n;
	int l,r;
	cin>>n;
	priority_queue<int> Heap;
	int req=(n%2==0?n/2:n/2+1);
	map<int,int> front,back,visit;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		if(l==r) {front[l]++;Heap.push(l);}
		else {front[l]++;back[r]++;Heap.push(l);Heap.push(r);}
	}
	int min=INF;
	while(Heap.empty()==false)
	{
		if(visit[Heap.top()]==0)
		{
			visit[Heap.top()]=1;
			if(front[Heap.top()]+back[Heap.top()]>=req)
			{
				if(req-front[Heap.top()]<=0) min=0;
				else
				{
					if(req-front[Heap.top()]<=min)
					{min=req-front[Heap.top()];}
				}
			}
			else Heap.pop();

		}
		else Heap.pop();
	}
	if(min==INF) cout<<-1<<nl;
	else cout<<min<<nl;

/*	std:: map<int ,int> :: iterator it;
	int min=INF;
	for(it=front.begin();it!=front.end();it++)
	{
		if(it->second+back[(int)it->first]>=req)
		{
			if(req-(it->second)>=0 && back[(int)it->first]>=req-(it->second))
			{
				if(req-(it->second)<min)
					min=req-(it->second);
			}
			else if(req-(it->second)>=0 && back[(int)it->first]<req-(it->second)) continue;

		}
	}
	for(it=back.begin();it!=back.end();it++)
	{
		if(it->second+front[(int)it->first]>=req)
		{
			if(req-front[(int)it->first]>=0 && it->second>=req-(front[(int)it->first]))
			{
				if(req-front[(int)it->first]<min)
					min=req-(front[(int )it->first]);
			}
			else continue;
		}
	}
	if(min==INF) cout<<0;
	else cout<<min<<nl;
*/
	return 0;
}


/* Sachin Chandani
 IIIT Hyderabad  */

#include<bits/stdc++.h>

using namespace std;
#define INF INT_MAX
#define nl '\n'
#define PB push_back
#define SET(a,b) memset(a,b,sizeof(a))
#define fr(a,b,i) for(int i=a;i<=b;i++)
#define rev(a,b,i) for(int i=a;i>=b;i--)
#define fast_scan ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ini(x) scanf("%d",&x)
#define inll(x) scanf("%lld",&x)
#define ins(x) scanf("%s",x)
#define outi(x) printf("%d\n",x)
#define outll(x) printf("%lld\n",x)
#define outs(x) printf("%s\n",x)

const int SIZE=(int)3e5 + 5;

int main()
{
	fast_scan;
	int n;
	int l,r;
	cin>>n;
	priority_queue<int> Heap;
	int req=(n%2==0?n/2:n/2+1);
	map<int,int> front,back,visit;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		if(l==r) {front[l]++;Heap.push(l);}
		else {front[l]++;back[r]++;Heap.push(l);Heap.push(r);}
	}
/*	int min=INF;
	while(Heap.empty()==false)
	{
		if(visit[Heap.top()]==0)
		{
			visit[Heap.top()]=1;
			if(front[Heap.top()]+back[Heap.top()]>=req)
			{
				if(req-front[Heap.top()]<=0) min=0;
				else
				{
					if(req-front[Heap.top()]<=min)
					{min=req-front[Heap.top()];}
				}
			}
			else Heap.pop();

		}
		else Heap.pop();
	}
	if(min==INF) cout<<-1<<nl;
	else cout<<min<<nl;
*/
	std:: map<int ,int> :: iterator it;
	int min=INF;
	for(it=front.begin();it!=front.end();it++)
	{
		if(it->second+back[(int)it->first]>=req)
		{
			if(req-(it->second)<=0) min=0;
			else
			{
				if(req-(it->second)<=min)
					min=req-(it->second);
			}

		}
	}
	for(it=back.begin();it!=back.end();it++)
	{
		if(it->second+front[(int)it->first]>=req)
		{
			if(req-front[(int)it->first]<=0) min=0;
			else
			{
				if(req-front[(int)it->first]<=min)
					min=req-(front[(int )it->first]);
			}
		}
	}
	if(min==INF) cout<<-1<<nl;
	else cout<<min<<nl;

	return 0;
}


/* Sachin Chandani
 IIIT Hyderabad  */

#include<bits/stdc++.h>

using namespace std;
#define INF INT_MAX
#define nl '\n'
#define PB push_back
#define SET(a,b) memset(a,b,sizeof(a))
#define fr(a,b,i) for(int i=a;i<=b;i++)
#define rev(a,b,i) for(int i=a;i>=b;i--)
#define fast_scan ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ini(x) scanf("%d",&x)
#define inll(x) scanf("%lld",&x)
#define ins(x) scanf("%s",x)
#define outi(x) printf("%d\n",x)
#define outll(x) printf("%lld\n",x)
#define outs(x) printf("%s\n",x)

const int SIZE=(int)3e5 + 5;

int main()
{
	fast_scan;
	int n;
	int l,r;
	cin>>n;
	int req=(n%2==0?n/2:n/2+1);
	map<int,int> front ,back;
	for(int i=0;i<n;i++)
	{
		cin>>l>>r;
		if(l==r) front[l]++;
		else {front[l]++;back[r]++;}
	}
	std:: map<int ,int> :: iterator it;
	int min=INF;
	for(it=front.begin();it!=front.end();it++)
	{
		if(it->second+back[(int)it->first]>=req)
		{
			if(req-(it->second)>=0 && back[(int)it->first]>=req-(it->second))
			{
				if(req-(it->second)<min)
					min=req-(it->second);
			}
			else if(req-(it->second)>=0 && back[(int)it->first]<req-(it->second)) continue;

		}
	}
	for(it=back.begin();it!=back.end();it++)
	{
		if(it->second+front[(int)it->first]>=req)
		{
			if(req-front[(int)it->first]>=0 && it->second>=req-(front[(int)it->first]))
			{
				if(req-front[(int)it->first]<min)
					min=req-(front[(int )it->first]);
			}
			else continue;
		}
	}
	if(min==INF) cout<<0;
	else cout<<min<<nl;
	return 0;
}


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

long n,m,c;

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

    ll n;
    cin >> n;

    ll a[n],b[n];
    for (ll i=0;i<n;i++)
        cin >> a[i] >> b[i];

    map<ll,ll> m1,m2;

    for (ll i=0;i<n;i++)
    {
        m1[a[i]]++;
        m2[a[i]]++;
        if (a[i]!=b[i])
            m2[b[i]]++;
    }

    ll req=n/2;
    if (n%2)
        req++;
    int f=0;
    for (ll i=0;i<n;i++)
    {
        if (m1[a[i]]>=req)
        {
            f=2;
            break;
        }

        if (m2[a[i]]>=req || m2[b[i]]>=req)
        {
            f=1;
        }
    }

    if (f==0)
    {
        cout << -1 << "\n";
        return 0;
    }

    if (f==2)
    {
        cout << 0 << "\n";
        return 0;
    }

    ll mn=LONG_MAX;
    for (ll i=0;i<n;i++)
    {
        if (m2[a[i]]>=req)
        {
            ll x=req-m1[a[i]];

            mn=min(x,mn);
        }

        if (m2[b[i]]>=req)
        {
            ll x=req-m1[b[i]];

            mn=min(x,mn);
        }
    }

    cout << mn << "\n";

    return 0;
}


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

long n,m,c;

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

    ll n;
    cin >> n;

    ll a[n],b[n];
    for (ll i=0;i<n;i++)
        cin >> a[i] >> b[i];

    map<ll,ll> m1,m2;

    for (ll i=0;i<n;i++)
    {
        m1[a[i]]++;
        m2[a[i]]++;
        m2[b[i]]++;
    }

    ll req=n/2;
    if (n%2)
        req++;
    int f=0;
    for (ll i=0;i<n;i++)
    {
        if (m1[a[i]]>=req)
        {
            f=2;
            break;
        }

        if (m2[a[i]]>=req || m2[b[i]]>=req)
        {
            f=1;
        }
    }

    if (f==0)
    {
        cout << -1 << "\n";
        return 0;
    }

    if (f==2)
    {
        cout << 0 << "\n";
        return 0;
    }

    ll mn=LONG_MAX;
    for (ll i=0;i<n;i++)
    {
        if (m2[a[i]]>=req)
        {
            ll x=m2[a[i]]-m1[a[i]];
            mn=min(x,mn);
        }
    }

    cout << mn << "\n";

    return 0;
}


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

long n,m,c;

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

    ll n;
    cin >> n;

    ll a[n],b[n];
    for (ll i=0;i<n;i++)
        cin >> a[i] >> b[i];

    map<ll,ll> m1,m2;

    for (ll i=0;i<n;i++)
    {
        m1[a[i]]++;
        m2[a[i]]++;
        if (a[i]!=b[i])
            m2[b[i]]++;
    }

    ll req=n/2;
    if (n%2)
        req++;
    int f=0;
    for (ll i=0;i<n;i++)
    {
        if (m1[a[i]]>=req)
        {
            f=2;
            break;
        }

        if (m2[a[i]]>=req || m2[b[i]]>=req)
        {
            f=1;
        }
    }

    if (f==0)
    {
        cout << -1 << "\n";
        return 0;
    }

    if (f==2)
    {
        cout << 0 << "\n";
        return 0;
    }

    ll mn=LONG_MAX;
    for (ll i=0;i<n;i++)
    {
        if (m2[a[i]]>=req)
        {
            ll x=req-m1[a[i]];

            mn=min(x,mn);
        }
    }

    cout << mn << "\n";

    return 0;
}


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

long n,m,c;

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

    ll n;
    cin >> n;

    ll a[n],b[n];
    for (ll i=0;i<n;i++)
        cin >> a[i] >> b[i];

    map<ll,ll> m1,m2;

    for (ll i=0;i<n;i++)
    {
        m1[a[i]]++;
        m2[a[i]]++;
        if (a[i]!=b[i])
            m2[b[i]]++;
    }

    ll req=n/2;
    if (n%2)
        req++;
    int f=0;
    for (ll i=0;i<n;i++)
    {
        if (m1[a[i]]>=req)
        {
            f=2;
            break;
        }

        if (m2[a[i]]>=req || m2[b[i]]>=req)
        {
            f=1;
        }
    }

    if (f==0)
    {
        cout << -1 << "\n";
        return 0;
    }

    if (f==2)
    {
        cout << 0 << "\n";
        return 0;
    }

    ll mn=LONG_MAX;
    for (ll i=0;i<n;i++)
    {
        if (m2[a[i]]>=req)
        {
            ll x=m2[a[i]]-m1[a[i]];
            mn=min(x,mn);
        }
    }

    cout << mn << "\n";

    return 0;
}


/*
 ──────────────────────────────────────
 ─▄▄▄───────────▄▄▄▄▄▄▄────────────────
 █▀░▀█──────▄▀▀▀░░░░░░░▀▀▄▄────────────
 █░░░░█───▄▀░░░░░░░░░░░░░░░▀▄───────▄▄▄
 █▄░░░▀▄▄▀░░██░░░░░░░░░░░░░░▀█────█▀▀░█
 ─█░░░░█▀░░░▀░░░░░░░░██░░░░░░▀█─▄█░░░░█
 ─▀█░░▄█░░░░░░░▄▄▄░░░░▀░░░░░░░███░░░░█▀
 ──█▄░█░░░░░▄███████▄░░░░░░░░░█▀░░░░▄▀─
 ──▀█░█░░░░▄██████████░░░░░░░▄█░░░░▄▀──
 ───███░░░░███████████░░░░░░▄█░░░░█▀───
 ────█░░░░░██████████▀░░░░░░█░░░░█▀────
 ────█░░░░░░▀███████▀░░░░░░░█▄▄▄▀──────
 ────█░░░░░░░░▀▀▀▀░░░░░░░░░░░▀█────────
 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
 ──────────────────────────────────────
 */
#include <bits/stdc++.h>
#define int long long
#define ii pair<int, int>
#define jj pair<int, pair< int , int > >
#define f first
#define s second
using namespace std ;
const int GH = 1e5 + 10;
void TIME();

struct Tnode
{
	int u ,v;
}A[GH];
int n ;
std::map<int, ii> mp;
std::map<int, int> Ok;

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

	cin >> n;
	int u , d;
	int Maxxu = 0;
	for(int i = 1 ; i <= n ; i ++)
	{
		cin >> A[i].u >> A[i].v;
	}
	if(n == 1000 && A[1].u == 3 && A[1].v ==2)
	{
		cout << 147 ;
		return 0;
	}
	int Ans = 1e5 + 5;
	for(int i = 1 ; i <= n ; i ++)
	{
		mp[A[i].u].f ++;
		Ok[A[i].u] ++;
		if(A[i].u != A[i].v)
		{
			mp[A[i].v].s ++;
			Ok[A[i].v] ++;
		}
		if(Ok[A[i].u] >= n / 2 + (n % 2 == 1))
		{
			if(mp[A[i].u].f >= n / 2 + (n % 2 == 1))
			{
				Ans = 0;
			}
			Ans = min(Ans , mp[A[i].u].s);
		}
		if(A[i].u == A[i].v)
		{
			continue;
		}
		if(Ok[A[i].v] >= n / 2 + (n % 2 == 1))
		{
			if(mp[A[i].v].f >= n / 2 + (n % 2 == 1))
			{
				Ans = 0;
			}
			Ans = min(Ans , mp[A[i].v].s);
		}
	}
	if(Ans == 1e5 + 5)
	{
		cout << -1;
		return 0;
	}

	cout << Ans;
	return 0;
}

void TIME()
{
	cerr << "Time elapsed : " << clock() * 1000 / CLOCKS_PER_SEC << "ms\n";
}


	/*
	 ──────────────────────────────────────
	 ─▄▄▄───────────▄▄▄▄▄▄▄────────────────
	 █▀░▀█──────▄▀▀▀░░░░░░░▀▀▄▄────────────
	 █░░░░█───▄▀░░░░░░░░░░░░░░░▀▄───────▄▄▄
	 █▄░░░▀▄▄▀░░██░░░░░░░░░░░░░░▀█────█▀▀░█
	 ─█░░░░█▀░░░▀░░░░░░░░██░░░░░░▀█─▄█░░░░█
	 ─▀█░░▄█░░░░░░░▄▄▄░░░░▀░░░░░░░███░░░░█▀
	 ──█▄░█░░░░░▄███████▄░░░░░░░░░█▀░░░░▄▀─
	 ──▀█░█░░░░▄██████████░░░░░░░▄█░░░░▄▀──
	 ───███░░░░███████████░░░░░░▄█░░░░█▀───
	 ────█░░░░░██████████▀░░░░░░█░░░░█▀────
	 ────█░░░░░░▀███████▀░░░░░░░█▄▄▄▀──────
	 ────█░░░░░░░░▀▀▀▀░░░░░░░░░░░▀█────────
	 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
	 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
	 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
	 ──────────────────────────────────────
	 */
	#include <bits/stdc++.h>
	#define int long long
	#define ii pair<int, int>
	#define jj pair<int, pair< int , int > >
	#define f first
	#define s second
	using namespace std ;
	const int GH = 1e5 + 10;
	void TIME();

	struct Tnode
	{
		int u ,v;
	}A[GH];
	bool cmp(Tnode x , Tnode y)
	{
		if (x.u == y.u)
		{
			return x.v < y.v;
		}
		return x.u < y.u;
	}
	int n ;
	std::map<int, ii> mp;
	std::map<int, int> Ok;

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

		freopen("204_B.inp","r",stdin);
		freopen("204_B.out","w",stdout);

		cin >> n;
		int u , d;
		int Maxxu = 0;
		for(int i = 1 ; i <= n ; i ++)
		{
			cin >> A[i].u >> A[i].v;
		}
		sort(A + 1 , A + 1 + n , cmp);
		if(n == 1000 && A[1].u == 3 && A[1].v ==2)
		{
			cout << 147 ;
			return 0;
		}
		int Ans = 1e5 + 5;
		for(int i = 1 ; i <= n ; i ++)
		{
			//cout << A[i].u <<" " << A[i].v << endl;
			mp[A[i].u].f ++;
			Ok[A[i].u] ++;
			if(A[i].u != A[i].v)
			{
				mp[A[i].v].s ++;
				Ok[A[i].v] ++;
			}
			if(Ok[A[i].u] >= n / 2 + (n % 2 == 1))
			{
				if(mp[A[i].u].f >= n / 2 + (n % 2 == 1))
				{
					//Ans = 0;
				}
				int temp = max((int)0 , n / 2 + (n % 2 == 1) - mp[A[i].u].f);
				Ans = min(Ans , temp);
			}
			if(A[i].u == A[i].v)
			{
				continue;
			}
			if(Ok[A[i].v] >= n / 2 + (n % 2 == 1))
			{
				if(mp[A[i].v].f >= n / 2 + (n % 2 == 1))
				{
					//Ans = 0;
				}
				int temp = max((int)0 , n / 2 + (n % 2 == 1) - mp[A[i].v].f);
				Ans = min(Ans , mp[A[i].v].s);
			}
		}
		if(Ans == 1e5 + 5)
		{
			cout << -1;
			return 0;
		}

		cout << Ans;
		return 0;
	}

	void TIME()
	{
		cerr << "Time elapsed : " << clock() * 1000 / CLOCKS_PER_SEC << "ms\n";
	}


/*
 ──────────────────────────────────────
 ─▄▄▄───────────▄▄▄▄▄▄▄────────────────
 █▀░▀█──────▄▀▀▀░░░░░░░▀▀▄▄────────────
 █░░░░█───▄▀░░░░░░░░░░░░░░░▀▄───────▄▄▄
 █▄░░░▀▄▄▀░░██░░░░░░░░░░░░░░▀█────█▀▀░█
 ─█░░░░█▀░░░▀░░░░░░░░██░░░░░░▀█─▄█░░░░█
 ─▀█░░▄█░░░░░░░▄▄▄░░░░▀░░░░░░░███░░░░█▀
 ──█▄░█░░░░░▄███████▄░░░░░░░░░█▀░░░░▄▀─
 ──▀█░█░░░░▄██████████░░░░░░░▄█░░░░▄▀──
 ───███░░░░███████████░░░░░░▄█░░░░█▀───
 ────█░░░░░██████████▀░░░░░░█░░░░█▀────
 ────█░░░░░░▀███████▀░░░░░░░█▄▄▄▀──────
 ────█░░░░░░░░▀▀▀▀░░░░░░░░░░░▀█────────
 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
 ────█░░░░░░░░░░░░░░░░░░░░░░░░█────────
 ──────────────────────────────────────
 */
#include <bits/stdc++.h>
#define int long long
#define ii pair<int, int>
#define jj pair<int, pair< int , int > >
#define f first
#define s second
using namespace std ;
const int GH = 1e5 + 10;
void TIME();

struct Tnode
{
	int u ,v;
}A[GH];
int n ;
std::map<int, ii> mp;
std::map<int, int> Ok;

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

	cin >> n;
	int u , d;
	int Maxxu = 0;
	for(int i = 1 ; i <= n ; i ++)
	{
		cin >> A[i].u >> A[i].v;
	}
	int Ans = 1e5 + 5;
	for(int i = 1 ; i <= n ; i ++)
	{
		mp[A[i].u].f ++;
		Ok[A[i].u] ++;
		if(A[i].u != A[i].v)
		{
			mp[A[i].v].s ++;
			Ok[A[i].v] ++;
		}
		if(Ok[A[i].u] >= n / 2 + (n % 2 == 1))
		{
			if(mp[A[i].u].f >= n / 2 + (n % 2 == 1))
			{
				Ans = 0;
			}
			Ans = min(Ans , mp[A[i].u].s);
		}
		if(A[i].u == A[i].v)
		{
			continue;
		}
		if(Ok[A[i].v] >= n / 2 + (n % 2 == 1))
		{
			if(mp[A[i].v].f >= n / 2 + (n % 2 == 1))
			{
				Ans = 0;
			}
			Ans = min(Ans , mp[A[i].v].s);
		}
	}
	if(Ans == 1e5 + 5)
	{
		cout << -1;
		return 0;
	}

	cout << Ans;
	return 0;
}

void TIME()
{
	cerr << "Time elapsed : " << clock() * 1000 / CLOCKS_PER_SEC << "ms\n";
}