using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

namespace Temp
{
    struct PointInt
    {
        public long X;

        public long Y;

        public PointInt(long x, long y)
            : this()
        {
            this.X = x;
            this.Y = y;
        }

        public static PointInt operator +(PointInt a, PointInt b)
        {
            return new PointInt(a.X + b.X, a.Y + b.Y);
        }

        public static PointInt operator -(PointInt a, PointInt b)
        {
            return new PointInt(a.X - b.X, a.Y - b.Y);
        }

        public static PointInt operator *(PointInt a, long k)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public static PointInt operator *(long k, PointInt a)
        {
            return new PointInt(k * a.X, k * a.Y);
        }

        public bool IsInsideRectangle(long l, long b, long r, long t)
        {
            return (l <= X) && (X <= r) && (b <= Y) && (Y <= t);
        }
    }

    struct LineInt
    {
        public LineInt(PointInt a, PointInt b)
            : this()
        {
            A = a.Y - b.Y;
            B = b.X - a.X;
            C = a.X * b.Y - a.Y * b.X;
        }

        public long A, B, C;

        public bool ContainsPoint(PointInt p)
        {
            return A * p.X + B * p.Y + C == 0;
        }
    }

    class MatrixInt
    {
        private long[,] m_Matrix;

        public int Size
        {
            get
            {
                return m_Matrix.GetLength(0) - 1;
            }
        }

        public long Mod { get; private set; }

        public MatrixInt(int size, long mod = 0)
        {
            m_Matrix = new long[size + 1, size + 1];
            Mod = mod;
        }

        public MatrixInt(long[,] matrix, long mod = 0)
        {
            this.m_Matrix = matrix;
            Mod = mod;
        }

        public static MatrixInt GetIdentityMatrix(int size, long mod = 0)
        {
            long[,] matrix = new long[size + 1, size + 1];

            for (int i = 1; i <= size; i++)
            {
                matrix[i, i] = 1;
            }

            return new MatrixInt(matrix, mod);
        }

        public long this[int i, int j]
        {
            get
            {
                return m_Matrix[i, j];
            }

            set
            {
                m_Matrix[i, j] = value;
            }
        }

        public static MatrixInt operator +(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);
            long[,] c = new long[n, n];
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    c[i, j] = a[i, j] + b[i, j];
                }
            }

            if (mod > 0)
            {
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= n; j++)
                    {
                        c[i, j] %= mod;
                    }
                }
            }

            return new MatrixInt(c, mod);
        }

        public static MatrixInt operator *(MatrixInt a, MatrixInt b)
        {
            int n = a.Size;
            long mod = Math.Max(a.Mod, b.Mod);

            long[,] c = new long[n, n];

            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int k = 1; k <= n; k++)
                    {
                        c[i, j] += a[i, k] * b[k, j];
                        if (mod > 0)
                        {
                            c[i, j] %= mod;
                        }
                    }
                }
            }

            return new MatrixInt(c, mod);
        }
    }

    static class Algebra
    {
        public static long Phi(long n)
        {
            long result = n;
            for (long i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    while (n % i == 0)
                    {
                        n /= i;
                    }

                    result -= result / i;
                }
            }

            if (n > 1)
            {
                result -= result / n;
            }

            return result;
        }

        public static long BinPower(long a, long n, long mod)
        {
            long result = 1;

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result = (result * a) % mod;
                }

                a = (a * a) % mod;
                n >>= 1;
            }

            return result;
        }

        public static class Permutations
        {
            public static int[] GetRandomPermutation(int n)
            {
                int[] p = new int[n];
                for (int i = 0; i < n; i++)
                {
                    p[i] = i;
                }

                Random random = new Random();
                for (int i = n - 1; i > 0; i--)
                {
                    int j = random.Next(i + 1);
                    int tmp = p[i];
                    p[i] = p[j];
                    p[j] = tmp;
                }

                return p;
            }
        }

        public static T[] Shuffle<T>(this T[] array)
        {
            int length = array.Length;
            int[] p = Permutations.GetRandomPermutation(length);
            T[] result = new T[length];
            for (int i = 0; i < length; i++)
            {
                result[i] = array[p[i]];
            }

            return result;
        }

        public static MatrixInt MatrixBinPower(MatrixInt a, long n)
        {
            MatrixInt result = new MatrixInt(a.Size);

            while (n > 0)
            {
                if ((n & 1) != 0)
                {
                    result *= a;
                }

                a *= a;
                n >>= 1;
            }

            return result;
        }

        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long ExtendedGcd(long a, long b, out long x, out long y)
        {
            if (b == 0)
            {
                x = 1;
                y = 0;
                return a;
            }

            long x1;
            long y1;
            long d = ExtendedGcd(b, a % b, out x1, out y1);
            x = y1;
            y = x1 - (a / b) * y1;
            return d;
        }

        public static long Lcm(long a, long b)
        {
            return (a / Gcd(a, b)) * b;
        }

        public static bool[] GetPrimes(int n)
        {
            n = Math.Max(n, 2);
            bool[] prime = new bool[n + 1];
            for (int i = 2; i <= n; i++)
            {
                prime[i] = true;
            }

            for (int i = 2; i * i <= n; i++)
            {
                if (prime[i])
                {
                    if ((long)i * i <= n)
                    {
                        for (int j = i * i; j <= n; j += i)
                        {
                            prime[j] = false;
                        }
                    }
                }
            }

            return prime;
        }

        public static long GetFibonacciNumber(long n, long mod = 0)
        {
            long[,] matrix = new long[,] { { 0, 0, 0 }, { 0, 0, 1 }, { 0, 1, 1 } };

            MatrixInt result = MatrixBinPower(new MatrixInt(matrix, mod), n);

            return result[2, 2];
        }

        public static long[] GetFibonacciSequence(int n)
        {
            long[] result = new long[n];
            result[0] = result[1] = 1;

            for (int i = 2; i < n; i++)
            {
                result[i] = result[i - 1] + result[i - 2];
            }

            return result;
        }

        public static long GetInverseElement(long a, long mod)
        {
            long x, y;
            long g = ExtendedGcd(a, mod, out x, out y);

            if (g != 1)
            {
                return -1;
            }

            return ((x % mod) + mod) % mod;
        }

        public static long[] GetAllInverseElements(long mod)
        {
            long[] result = new long[mod];
            result[1] = 1;
            for (int i = 2; i < mod; i++)
            {
                result[i] = (mod - (((mod / i) * result[mod % i]) % mod)) % mod;
            }

            return result;
        }
    }

    internal static class Reader
    {
        public static void ReadInt(out int a)
        {
            int[] number = new int[1];
            ReadInt(number);
            a = number[0];
        }

        public static void ReadInt(out int a, out int b)
        {
            int[] numbers = new int[2];
            ReadInt(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadInt(out int int1, out int int2, out int int3)
        {
            int[] numbers = new int[3];
            ReadInt(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static void ReadInt(out int int1, out int int2, out int int3, out int int4)
        {
            int[] numbers = new int[4];
            ReadInt(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
            int4 = numbers[3];
        }

        public static void ReadLong(out long a)
        {
            long[] number = new long[1];
            ReadLong(number);
            a = number[0];
        }

        public static void ReadLong(out long a, out long b)
        {
            long[] numbers = new long[2];
            ReadLong(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadLong(out long int1, out long int2, out long int3)
        {
            long[] numbers = new long[3];
            ReadLong(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static void ReadLong(out long int1, out long int2, out long int3, out long int4)
        {
            long[] numbers = new long[4];
            ReadLong(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
            int4 = numbers[3];
        }

        public static void ReadInt(int[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = int.Parse(list[i]);
            }
        }

        public static int[] ReadDigits()
        {
            // ReSharper disable AssignNullToNotNullAttribute
            return Console.ReadLine().Select(x => int.Parse(x.ToString())).ToArray();
            // ReSharper restore AssignNullToNotNullAttribute
        }

        public static void ReadLong(long[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = long.Parse(list[i]);
            }
        }

        public static void ReadDouble(double[] numbers)
        {
            // ReSharper disable PossibleNullReferenceException
            var list = Console.ReadLine().Split();
            // ReSharper restore PossibleNullReferenceException

            int count = Math.Min(numbers.Length, list.Length);

            for (int i = 0; i < count; i++)
            {
                numbers[i] = double.Parse(list[i]);
            }
        }

        public static void ReadDouble(out double a, out double b)
        {
            double[] numbers = new double[2];
            ReadDouble(numbers);
            a = numbers[0];
            b = numbers[1];
        }

        public static void ReadDouble(out double int1, out double int2, out double int3)
        {
            double[] numbers = new double[3];
            ReadDouble(numbers);
            int1 = numbers[0];
            int2 = numbers[1];
            int3 = numbers[2];
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }
    }

    static class MyMath
    {
        public static int GetMinimalPrimeDivisor(int n)
        {
            for (int i = 2; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    return i;
                }
            }

            return n;
        }

        public static long Sqr(long x)
        {
            return x * x;
        }
    }

    public interface IGraph
    {
        int Vertices  { get; set; }

        IList<int> this[int i] { get; }

        void AddEdge(int u, int v);

        void AddOrientedEdge(int u, int v);
    }

    public class Graph : IGraph
    {
        private List<int>[] m_Edges;

        public int Vertices { get; set; }

        public IList<int> this[int i]
        {
            get
            {
                return this.m_Edges[i];
            }
        }

        public Graph(int vertices)
        {
            this.Vertices = vertices;

            this.m_Edges = new List<int>[vertices];

            for (int i = 0; i < vertices; i++)
            {
                this.m_Edges[i] = new List<int>();
            }
        }

        public void AddEdge(int u, int v)
        {
            this.AddOrientedEdge(u, v);
            this.AddOrientedEdge(v, u);
        }

        public void AddOrientedEdge(int first, int second)
        {
            this.m_Edges[first].Add(second);
        }

        public int[] Bfs(int start)
        {
            int[] d = new int[Vertices];
            for (int i = 0; i < Vertices; i++)
            {
                d[i] = -1;
            }

            Queue<int> queue = new Queue<int>();
            queue.Enqueue(start);
            d[start] = 0;

            while (queue.Count > 0)
            {
                int v = queue.Dequeue();
                foreach (int t in this.m_Edges[v].Where(t => d[t] == -1))
                {
                    queue.Enqueue(t);
                    d[t] = d[v] + 1;
                }
            }

            return d;
        }
    }

    class SimpleSumTable
    {
        private readonly int[,] m_Sum;

        public SimpleSumTable(int n, int m, int[,] table)
        {
            m_Sum = new int[n + 1, m + 1];

            for (int i = 1; i < n + 1; i++)
            {
                for (int j = 1; j < m + 1; j++)
                {
                    m_Sum[i, j] = m_Sum[i, j - 1] + m_Sum[i - 1, j] - m_Sum[i - 1, j - 1] + table[i, j];
                }
            }
        }

        public int GetSum(int l, int b, int r, int t)
        {
            return m_Sum[r, t] - m_Sum[r, b] - m_Sum[l, t] + m_Sum[l, b];
        }
    }

    class SegmentTreeSimpleInt<T>
    {
        public int Size { get; private set; }

        private readonly T[] m_Tree;

        private Func<T, T, T> m_Operation;

        private T m_Null;

        public SegmentTreeSimpleInt(int size, Func<T, T, T> operation, T nullElement, IList<T> array = null)
        {
            this.Size = size;
            this.m_Operation = operation;
            this.m_Null = nullElement;

            m_Tree = new T[4 * size];
            if (array != null)
            {
                this.Build(array, 1, 0, size - 1);
            }
        }

        private void Build(IList<T> array, int v, int tl, int tr)
        {
            if (tl == tr)
            {
                m_Tree[v] = array[tl];
            }
            else
            {
                int tm = (tl + tr) / 2;
                this.Build(array, 2 * v, tl, tm);
                this.Build(array, 2 * v + 1, tm + 1, tr);
                this.CalculateNode(v);
            }
        }

        public T GetSum(int l, int r)
        {
            return GetSum(1, 0, Size - 1, l, r);
        }

        private T GetSum(int v, int tl, int tr, int l, int r)
        {
            if (l > r)
            {
                return m_Null;
            }

            if (l == tl && r == tr)
            {
                return m_Tree[v];
            }

            int tm = (tl + tr) / 2;

            return this.m_Operation(GetSum(2 * v, tl, tm, l, Math.Min(r, tm)),GetSum(2 * v + 1, tm + 1, tr, Math.Max(l, tm + 1), r));
        }

        public void Update(int pos, T newValue)
        {
            Update(1, 0, Size - 1, pos, newValue);
        }

        private void Update(int v, int tl, int tr, int pos, T newValue)
        {
            if (tl == tr)
            {
                m_Tree[v] = newValue;
            }
            else
            {
                int tm = (tl + tr) / 2;
                if (pos <= tm)
                {
                    Update(2 * v, tl, tm, pos, newValue);
                }
                else
                {
                    Update(2 * v + 1, tm + 1, tr, pos, newValue);
                }
                this.CalculateNode(v);
            }
        }

        private void CalculateNode(int v)
        {
            m_Tree[v] = this.m_Operation(m_Tree[2 * v], m_Tree[2 * v + 1]);
        }
    }

    struct Pair<TFirst, TSecond>
    {
        public Pair(TFirst first, TSecond second)
            : this()
        {
            this.First = first;
            this.Second = second;
        }

        public TFirst First { set; get; }

        public TSecond Second { set; get; }
    }

    internal class AccumulativeDictionary<TKey> : Dictionary<TKey, int>
    {
        public new void Add(TKey key, int value = 1)
        {
            if (this.ContainsKey(key))
            {
                base[key] += value;
            }
            else
            {
                base.Add(key, value);
            }
        }

        public new int this[TKey key]
        {
            get
            {
                return this.ContainsKey(key) ? base[key] : 0;
            }
            set
            {
                this.Add(key, value);
            }
        }
    }

    class Program
    {
        private static StreamReader m_InputStream;

        private static StreamWriter m_OutStream;

        private static void OpenFiles()
        {
            m_InputStream = File.OpenText("input.txt");
            Console.SetIn(m_InputStream);

            m_OutStream = File.CreateText("output.txt");
            Console.SetOut(m_OutStream);
        }

        private static void CloseFiles()
        {
            m_OutStream.Flush();

            m_InputStream.Dispose();
            m_OutStream.Dispose();
        }

        static void Main()
        {
            //OpenFiles();

            new Solution().Solve();

            //CloseFiles();
        }
    }

    internal class Solution
    {
        public void Solve()
        {
            var t = new AccumulativeDictionary<int>();
            var b = new AccumulativeDictionary<int>();

            int n;
            Reader.ReadInt(out n);
            for (int i = 0; i < n; i++)
            {
                int x, y;
                Reader.ReadInt(out x, out y);

                t.Add(x);
                if (x != y)
                {
                    b.Add(y);
                }
            }

            int ans = -1;

            foreach (var pair in t)
            {
                int sum = pair.Value + b[pair.Key];
                if (2 * sum >= n)
                {
                    if (ans == -1 || ans > (n + 1) / 2 - pair.Value)
                    {
                        ans = Math.Max(0, (n + 1) / 2 - pair.Value);
                    }
                }
            }

            foreach (var pair in b)
            {
                int sum = pair.Value + t[pair.Key];
                if (2 * sum >= n)
                {
                    if (ans == -1 || ans > (n + 1) / 2 - t[pair.Key])
                    {
                        ans = Math.Max(0, (n + 1) / 2 - t[pair.Key]);
                    }
                }
            }

            Console.WriteLine(ans);
        }
    }
}


d=dict()
n=int(input())
for i in range(n):
    f,b=map(int,input().split())
    if f not in d:d[f]=[0,0]
    d[f][0]+=1
    if f!=b:
        if b not in d:d[b]=[0,0]
        d[b][1]+=1
n=(n+1)//2
m=2*n
for aa,a in d.items():
    if sum(a)>=n:
        m=min(m,n-a[0])
if m==2*n:print(-1)
else: print(max(0,m))


d=dict()
n=int(input())
for i in range(n):
    f,b=map(int,input().split())
    if f not in d:d[f]=[0,0]
    d[f][0]+=1
    if f!=b:
        if b not in d:d[b]=[0,0]
        d[b][1]+=1
n=(n+1)//2
m=n
for aa,a in d.items():
    if sum(a)>=n:
        m=min(m,n-a[0])
print(max(0,m))


from collections import defaultdict
from math import ceil
d= defaultdict(list)
n = int(input())
for i in range(n):
    a,b =map(int,input().split())
    if a==b:
        if a in d:
            d[a][0]+=1
        else:
            d[a]=[1,0]
    else:
        if a in d:
            d[a][0]+=1
        else:
            d[a] =[1,0]
        if b in d:
            d[b][1]+=1
        else:
            d[b] = [0,1]
m= ceil(n/2)
#print(d)
mini = 1e6
for i in d:
    a =d[i][0]
    b=  d[i][1]
    if a+b>=m:
        if a>=m:
            mini= min(0,mini)
        else:
            mini = min(m-a,mini)
if mini ==1e6:
    print(-1)
else:
    print(mini)


from collections import defaultdict
from math import ceil
d= defaultdict(list)
n = int(input())
for i in range(n):
    a,b =map(int,input().split())
    if a==b:
        if a in d:
            d[a][0]+=1
    else:
        if a in d:
            d[a][0]+=1
        else:
            d[a] =[1,0]
        if b in d:
            d[b][1]+=1
        else:
            d[b] = [0,1]
m= ceil(n/2)
mini = 1e6
for i in d:
    a =d[i][0]
    b=  d[i][1]
    if a+b>=m:
        if a>=m:
            mini= min(0,mini)
        else:
            mini = min(m-a,mini)
if mini ==1e6:
    print(-1)
else:
    print(mini)


from math import ceil
n=int(input())
front=[]
back=[]
dfront={}
dback={}
for i in range(n):
    a,b=map(int,input().split())
    if a==b:
        if a in dfront:
            dfront[a]+=1
        else:
            dfront[a]=1
    else:
        if a in dfront:
            dfront[a]+=1
        else:
            dfront[a]=1
        if b in dback:
            dback[b]+=1
        else:
            dback[b]=1
m=10**10
f=0
for i in dfront:
    if dfront[i]>=ceil(n/2):
        f=1
        break
    else:
        temp=ceil(n/2)-dfront[i]
        if i in dback:
            if dback[i]>=temp:
                m=min(m,temp)
if f==1:
    print(0)
else:
    g=1
    for i in dback:
        if i not in dfront and dback[i]>=ceil(n/2):
            g=0
            m=min(m,ceil(n/2))
    if m==10**10:
        print(-1)
    else:
        print(m)


from math import ceil
n=int(input())
front=[]
back=[]
dfront={}
dback={}
for i in range(n):
    a,b=map(int,input().split())
    front.append(a)
    back.append(b)
for i in range(n):
    if front[i]==back[i]:
        if front[i] in dfront:
            dfront[front[i]]+=1
        else:
            dfront[front[i]]=1
    else:
        if front[i] in dfront:
            dfront[front[i]]+=1
        else:
            dfront[front[i]]=1
        if back[i] in dback:
            dback[back[i]]+=1
        else:
            dback[back[i]]=1
m=10**10
f=0
for i in dfront:
    if dfront[i]>=ceil(n/2):
        f=1
        break
    else:
        temp=ceil(n/2)-dfront[i]
        if i in dback:
            if dback[i]>=temp:
                m=min(m,temp)
if f==1:
    print(0)
else:
    g=1
    for i in dback:
        if i not in dfront and dback[i]>=ceil(n/2):
            g=0
            m=min(m,ceil(n/2))
    if m==10**10:
        print(-1)
    else:
        print(m)


# cook your dish here
import math

n = int(input())
front = {}
back = {}
same = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == y:
        same[x] = same.get(x, 0)+1
    else:
        front[x] = front.get(x, 0)+1
        back[y] = back.get(y, 0)+1

ans = -1

for k in same.keys():
    if same[k] >= math.ceil(n/2):
        ans = 0

for k in front.keys():
    moves = back.get(k, 0)
    cards = front[k]

    if k in same.keys():
        cards += same[k]

    if (cards >= math.ceil(n/2)):
        ans = 0
        continue

    if (cards+moves >= math.ceil(n/2)):
        if (ans == -1 or ans < moves):
            ans = moves

for k in back.keys():
    moves = back[k]
    if k in front.keys():
        cards += front[k]
    if k in same.keys():
        cards += same[k]

    if (cards >= math.ceil(n/2)):
        ans = 0
        continue

    if (cards+back[k] >= math.ceil(n/2)):
        if (ans == -1 or ans < moves):
            ans = moves

print(ans)


# cook your dish here
import math

n = int(input())
front = {}
back = {}
same = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == y:
        same[x] = same.get(x, 0)+1
    else:
        front[x] = front.get(x, 0)+1
        back[y] = back.get(y, 0)+1

ans = -1

for k in same.keys():
    if same[k] >= math.ceil(n/2):
        ans = 0

for k in front.keys():
    cards = front[k]
    if k in same.keys():
        cards += same[k]

    avl = 0
    if k in back.keys():
        avl = back[k]

    if (cards+avl >= math.ceil(n/2)):
        moves = min(avl, max(0, math.ceil(n/2)-cards))
        if (ans == -1 or moves < ans):
            ans = moves

for k in back.keys():
    avl = back[k]

    cards = 0
    if k in front.keys():
        cards += front[k]
    if k in same.keys():
        cards += same[k]

    if (cards+avl >= math.ceil(n/2)):
        moves = min(avl, max(0, math.ceil(n/2)-cards))
        if (ans == -1 or moves < ans):
            ans = moves

print(ans)


# cook your dish here
import math

n = int(input())
front = {}
back = {}
same = {}
for i in range(n):
    x, y = map(int, input().split())
    if x == y:
        same[x] = same.get(x, 0)+1
    else:
        front[x] = front.get(x, 0)+1
        back[y] = back.get(y, 0)+1

ans = -1

for k in same.keys():
    if same[k] >= math.ceil(n/2):
        ans = 0

for k in front.keys():
    moves = 0
    if k in back.keys():
        moves = back[k]

    cards = front[k]
    if k in same.keys():
        cards += same[k]

    if (cards >= math.ceil(n/2)):
        ans = 0
        continue

    if (cards+moves >= math.ceil(n/2)):
        if (ans == -1 or ans < moves):
            ans = moves

for k in back.keys():
    moves = back[k]
    cards = 0
    if k in front.keys():
        cards += front[k]
    if k in same.keys():
        cards += same[k]

    if (cards >= math.ceil(n/2)):
        ans = 0
        continue

    if (cards+moves >= math.ceil(n/2)):
        if (ans == -1 or ans < moves):
            ans = moves

print(ans)


# Author : raj1307 - Raj Singh
# Date   : 01.09.2020

from __future__ import division, print_function

import os,sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def ii():  return int(input())
def si():  return input()
def mi():  return map(int,input().strip().split(" "))
def msi(): return map(str,input().strip().split(" "))
def li():  return list(mi())

def dmain():
    sys.setrecursionlimit(1000000)
    threading.stack_size(1024000)
    thread = threading.Thread(target=main)
    thread.start()

#from collections import deque, Counter, OrderedDict,defaultdict
#from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace
#from math import log,sqrt,factorial,cos,tan,sin,radians
#from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
#from decimal import *
#import threading
#from itertools import permutations
#Copy 2D list  m = [x[:] for x in mark] .. Avoid Using Deepcopy

abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def getKey(item): return item[1]
def sort2(l):return sorted(l, key=getKey,reverse=True)
def d2(n,m,num):return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo (x): return (x and (not(x & (x - 1))) )
def decimalToBinary(n): return bin(n).replace("0b","")
def ntl(n):return [int(i) for i in str(n)]
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))

def ceil(x,y):
    if x%y==0:
        return x//y
    else:
        return x//y+1

def powerMod(x,y,p):
    res = 1
    x %= p
    while y > 0:
        if y&1:
            res = (res*x)%p
        y = y>>1
        x = (x*x)%p
    return res

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

def read():
    sys.stdin  = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')

def main():

    #for _ in range(ii()):

    n=ii()
    f={}
    g={}

    l=[]

    for i in range(n):

        x,y=mi()

        l.append(x)
        l.append(y)

        if f.get(x,0)==0:
            f[x]=0

        f[x]+=1

        if g.get(y,0)==0:
            g[y]=0

        if x!=y:
            g[y]+=1

    ans=inf

    for i in range(len(l)):

        need = ceil(n,2)

        a=f.get(l[i],0)
        b=g.get(l[i],0)

        if a+b>=need:

            ans=min(ans,max(need-a,0))

    if ans==inf:
        print(-1)
    else:
        print(ans)

# region fastio
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    #read()
    main()
    #dmain()

# Comment Read()


from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#it=iter(t)
#if all(c in it for c in s):
#ls.sort(key=lambda x: (x[0], x[1]))
#n,k= map(int, input().split())
# ls=list(map(int,input().split()))
# for i in range(m):
import math
#n,k= map(int, input().split())
#ls=list(map(int,input().split()))
x=int(input())
d={}
ls={}
for i in range(x):
    n,k= map(int, input().split())
    if n not in ls:
        ls[n]=1
    else:
        ls[n]+=1
    if k not in d:
        d[k]=1
    else:
        d[k]+=1
var=x//2
if x%2!=0:
    var+=1
ans=-1
for i in ls:
    if i in d:
        if ls[i]+d[i]>=var:
            ans=min(ans,max(0,var-ls[i]))
    else:
        if ls[i]>=var:
            ans=0
if ans!=-1:
    print(ans)
else:
    for i in d:
        if d[i]>=var:
            print(0)
            exit()
    print(-1)

#arr=list(map(int,input().split()))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#it=iter(t)
#if all(c in it for c in s):
#ls.sort(key=lambda x: (x[0], x[1]))
#n,k= map(int, input().split())
# ls=list(map(int,input().split()))
# for i in range(m):
import math
#n,k= map(int, input().split())
#ls=list(map(int,input().split()))
x=int(input())
d={}
ls={}
for i in range(x):
    n,k= map(int, input().split())
    if n not in ls:
        ls[n]=1
    else:
        ls[n]+=1
    if k not in d:
        d[k]=1
    else:
        d[k]+=1
var=x//2
if x%2!=0:
    var+=1
ans=var
for i in ls:
    if i in d:
        if ls[i]+d[i]>=var:
            ans=min(ans,max(0,var-ls[i]))
    else:
        if ls[i]>=var:
            ans=0
print(ans)

#arr=list(map(int,input().split()))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#it=iter(t)
#if all(c in it for c in s):
#ls.sort(key=lambda x: (x[0], x[1]))
#n,k= map(int, input().split())
# ls=list(map(int,input().split()))
# for i in range(m):
import math
#n,k= map(int, input().split())
#ls=list(map(int,input().split()))
x=int(input())
d={}
ls={}
same={}
for i in range(x):
    n,k= map(int, input().split())
    if n==k:
        if n in same:
            same[n]+=1
        else:
            same[n]=1

    if n not in ls:
        ls[n]=1
    else:
        ls[n]+=1
    if k not in d:
        d[k]=1
    else:
        d[k]+=1
var=x//2
if x%2!=0:
    var+=1
ans=var
f=0

for i in ls:
    if i in d:
        value=ls[i]+d[i]
        if i in same:
            value-=same[i]
        if value>=var:
            ans=min(ans,max(0,var-ls[i]))
            f=1
    else:
        if ls[i]>=var:
            ans=0
            break
if f==1:
    print(ans)
else:
    for i in d:
        if d[i]>=var:
            print(var)
            exit()
    print(-1)

#arr=list(map(int,input().split()))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#it=iter(t)
#if all(c in it for c in s):
#ls.sort(key=lambda x: (x[0], x[1]))
#n,k= map(int, input().split())
# ls=list(map(int,input().split()))
# for i in range(m):
import math
#n,k= map(int, input().split())
#ls=list(map(int,input().split()))
x=int(input())
d={}
ls={}
same={}
for i in range(x):
    n,k= map(int, input().split())
    if n==k:
        if n in same:
            same[n]+=1
        else:
            same[n]=1

    if n not in ls:
        ls[n]=1
    else:
        ls[n]+=1
    if k not in d:
        d[k]=1
    else:
        d[k]+=1
var=x//2
if x%2!=0:
    var+=1
ans=var
f=0

for i in ls:
    if i in d:
        value=ls[i]+d[i]
        if i in same:
            value-=same[i]
        if value>=var:
            ans=min(ans,max(0,var-ls[i]))
            f=1
    else:
        if ls[i]>=var:
            ans=0
            f=1
            break
if f==1:
    print(ans)
else:
    for i in d:
        if d[i]>=var:
            print(var)
            exit()
    print(-1)

#arr=list(map(int,input().split()))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#it=iter(t)
#if all(c in it for c in s):
#ls.sort(key=lambda x: (x[0], x[1]))
#n,k= map(int, input().split())
# ls=list(map(int,input().split()))
# for i in range(m):
import math
#n,k= map(int, input().split())
#ls=list(map(int,input().split()))
x=int(input())
d={}
ls={}
for i in range(x):
    n,k= map(int, input().split())
    if n not in ls:
        ls[n]=1
    else:
        ls[n]+=1
    if k not in d:
        d[k]=1
    else:
        d[k]+=1
var=x//2
if x%2!=0:
    var+=1
ans=var
f=0
for i in ls:
    if i in d:
        if ls[i]+d[i]>=var:
            ans=min(ans,max(0,var-ls[i]))
            f=1
    else:
        if ls[i]>=var:
            ans=0
if f==1:
    print(ans)
else:
    for i in d:
        if d[i]>=var:
            print(0)
            exit()
    print(-1)

#arr=list(map(int,input().split()))


from collections import Counter
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#it=iter(t)
#if all(c in it for c in s):
#ls.sort(key=lambda x: (x[0], x[1]))
#n,k= map(int, input().split())
# ls=list(map(int,input().split()))
# for i in range(m):
import math
#n,k= map(int, input().split())
#ls=list(map(int,input().split()))
x=int(input())
d={}
ls={}
same={}
for i in range(x):
    n,k= map(int, input().split())
    if n==k:
        if n in same:
            same[n]+=1
        else:
            same[n]=1

    if n not in ls:
        ls[n]=1
    else:
        ls[n]+=1
    if k not in d:
        d[k]=1
    else:
        d[k]+=1
var=x//2
if x%2!=0:
    var+=1
ans=var
f=0

for i in ls:
    if i in d:
        value=ls[i]+d[i]
        if i in same:
            value-=same[i]
        if value>=var:
            ans=min(ans,max(0,var-ls[i]))
            f=1
    else:
        if ls[i]>=var:
            ans=0
            break
if f==1:
    print(ans)
else:
    for i in d:
        if d[i]>=var:
            print(0)
            exit()
    print(-1)

#arr=list(map(int,input().split()))


import sys
from math import *
input=sys.stdin.readline

#n,m,k=map(int,input().split())
d={}
n=int(input())
for i in range(n):
    x,y=map(int,input().split())
    if x in d:
        d[x][0]+=1
    else:
        d[x]=[1,0]
    if x==y:
        continue
    if y in d:
        d[y][1]+=1
    else:
        d[y]=[0,1]
mini=10**15
for i in d:
    if int(ceil(n/2))-d[i][0]<=d[i][1]:
        mini=min(mini,max(0,int(ceil(n/2))-d[i][0]))
if mini!=10**15:
    print(mini  )
else :
    print(-1)


import sys
from math import *
input=sys.stdin.readline

#n,m,k=map(int,input().split())
d={}
n=int(input())
for i in range(n):
    x,y=map(int,input().split())
    if x in d:
        d[x][0]+=1
    else:
        d[x]=[1,0]
    if y in d:
        d[y][1]+=1
    else:
        d[y]=[0,1]
mini=10**15
for i in d:
    if int(ceil(n/2))-d[i][0]<=d[i][1]:
        mini=min(mini,max(0,int(ceil(n/2))-d[i][0]))
if mini!=10**15:
    print(mini  )
else :
    print(-1)


"""
    Author - Satwik Tiwari .
    20th Oct , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.

from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key

# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil

from copy import deepcopy
from collections import deque

from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect

#==============================================================================================
#fast I/O region
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

#===============================================================================================
#some shortcuts

def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for pp in range(t):
        solve(pp)
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def google(p):
    print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
    res = 1     # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) : # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1      # y = y/2
        x = (x * x) % p
    return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True
inf = pow(10,20)
mod = 998244353
#===============================================================================================
# code here ;))

def solve(case):
    n = int(inp())
    ff = {}
    ss = {}

    for i in range(n):
        a,b = sep()
        if(a not in ff):
            ff[a] = 1
        else:
            ff[a] +=1

        if(b not in ss):
            ss[b] = 1
        else:
            ss[b] +=1

    ans = inf
    for i in ff:
        curr = ff[i]
        if(curr>=ceil(n/2)):
            ans = min(ans,0)
        rem = ceil(n/2) - curr

        if(i in ss and ss[i]>=rem):
            ans = min(ans,rem)

    print(ans if ans!=inf else -1)

testcase(1)
# testcase(int(inp()))


"""
    Author - Satwik Tiwari .
    20th Oct , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.

from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key

# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil

from copy import deepcopy
from collections import deque

from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect

#==============================================================================================
#fast I/O region
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

#===============================================================================================
#some shortcuts

def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for pp in range(t):
        solve(pp)
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def google(p):
    print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
    res = 1     # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) : # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1      # y = y/2
        x = (x * x) % p
    return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True
inf = pow(10,20)
mod = 998244353
#===============================================================================================
# code here ;))

def solve(case):
    n = int(inp())
    ff = {}
    ss = {}

    for i in range(n):
        a,b = sep()
        if(a not in ff):
            ff[a] = 1
        else:
            ff[a] +=1

        if(b not in ss):
            ss[b] = 1
        else:
            ss[b] +=1

    ans = inf
    for i in ff:
        curr = ff[i]
        # print(curr)
        if(curr>=ceil(n/2)):
            ans = min(ans,0)
        # print(ans)
        rem = ceil(n/2) - curr

        if(i in ss and ss[i]>=rem):
            ans = min(ans,abs(rem))
    for i in ss:
        if(i in ff):
            continue
        curr = ss[i]
        if(curr>=ceil(n/2)):
            ans = min(ans,ceil(n/2))

    print(ans if ans!=inf else -1)

testcase(1)
# testcase(int(inp()))


"""
    Author - Satwik Tiwari .
    20th Oct , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.

from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key

# from itertools import *
from heapq import *
from math import gcd, factorial,floor,ceil

from copy import deepcopy
from collections import deque

from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect

#==============================================================================================
#fast I/O region
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
  def wrapped_func(*args, **kwargs):
    if stack: return f(*args, **kwargs)
    to = f(*args, **kwargs)
    while True:
      if type(to) is GeneratorType:
        stack.append(to)
        to = next(to)
        continue
      stack.pop()
      if not stack: break
      to = stack[-1].send(to)
    return to
  return wrapped_func
#### END ITERATE RECURSION ####

#===============================================================================================
#some shortcuts

def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for pp in range(t):
        solve(pp)
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def google(p):
    print('Case #'+str(p)+': ',end='')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(x, y, p) :
    res = 1     # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) : # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1      # y = y/2
        x = (x * x) % p
    return res
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True
inf = pow(10,20)
mod = 998244353
#===============================================================================================
# code here ;))

def solve(case):
    n = int(inp())
    ff = {}
    ss = {}

    for i in range(n):
        a,b = sep()
        if(a not in ff):
            ff[a] = 1
        else:
            ff[a] +=1
        if(a == b):
            continue

        if(b not in ss):
            ss[b] = 1
        else:
            ss[b] +=1

    ans = inf
    for i in ff:
        curr = ff[i]
        # print(curr)
        if(curr>=ceil(n/2)):
            ans = min(ans,0)
        # print(ans)
        rem = ceil(n/2) - curr

        if(i in ss and ss[i]>=rem):
            ans = min(ans,abs(rem))
    for i in ss:
        if(i in ff):
            continue
        curr = ss[i]
        if(curr>=ceil(n/2)):
            ans = min(ans,ceil(n/2))

    print(ans if ans!=inf else -1)

testcase(1)
# testcase(int(inp()))


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def li():
	return [int(x) for x in input().split()]
def fi():
	return int(input())
def si():
	return list(input().rstrip())
def mi():
	return 	map(int,input().split())
def gh():
	sys.stdout.flush()
def bo(i):
	return ord(i)-ord('a')
from copy import *
from bisect import *

from itertools import permutations

t=1

while t>0:
	t-=1
	n=fi()
	d={}
	for i in range(n):
		x,y=mi()
		if x not in d:
			d[x]=[0,0,0]
		d[x][0]+=1
		if y not in d:
			d[y]=[0,0,0]
		d[y][1]+=1
		if x==y:
			d[x][2]+=1
	mini=10**18
	p=int(ceil(n/2))

	for i in d:
		if d[i][0]+d[i][1]-d[i][2]>=p:
			mini=min(mini,max(0,p-d[i][0]))

	print(mini if mini<10**18 else -1)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
from math import *
import copy
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def li():
	return [int(x) for x in input().split()]
def fi():
	return int(input())
def si():
	return list(input().rstrip())
def mi():
	return 	map(int,input().split())
def gh():
	sys.stdout.flush()
def bo(i):
	return ord(i)-ord('a')
from copy import *
from bisect import *

from itertools import permutations

t=1

while t>0:
	t-=1
	n=fi()
	d={}
	for i in range(n):
		x,y=mi()
		if x not in d:
			d[x]=[0,0]
		d[x][0]+=1
		x=y
		if x not in d:
			d[x]=[0,0]
		d[x][1]+=1
	mini=10**18
	p=int(ceil(n/2))

	for i in d:
		if d[i][0]+d[i][1]>=p:
			mini=min(mini,max(0,p-d[i][0]))

	print(mini if mini<10**18 else -1)


import java.util.*;
import java.io.*;

public class Main{

    BufferedReader in;
    StringTokenizer str = null;
    PrintWriter out;

    private String next() throws Exception{
    	if (str == null || !str.hasMoreElements())
    	    str = new StringTokenizer(in.readLine());
    	return str.nextToken();
    }

    private int nextInt() throws Exception{
	   return Integer.parseInt(next());
    }

    public void run() throws Exception{
    	in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);

	int n = nextInt();
	int k = nextInt();
	int r = 0;
	for(int step=0;step<n;step++){
	    String x = next();
	    boolean []a = new boolean[10];
	    for(int i=0;i<x.length();i++){
		a[x.charAt(i)-'0'] = true;
	    }

	    boolean valid = true;
	    for(int i=0;i<10;i++){
		if (!a[i] && i <= k){
		    valid = false;
		}
	    }

	    r+=(valid) ? 1 : 0;
	}

	out.println(r);
	out.close();
    }

    public static void main(String args[]) throws Exception{
	   new Main().run();
    }
}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution implements Runnable {

        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        public static void main(String[] args) {
                new Thread(null, new Solution(), "", 256 * (1L << 20)).start();
        }

        public void run() {
                try {
                        long t1 = System.currentTimeMillis();
                        if (System.getProperty("ONLINE_JUDGE") != null) {
                                in = new BufferedReader(new InputStreamReader(System.in));
                                out = new PrintWriter(System.out);
                        } else {
                                in = new BufferedReader(new FileReader("input.txt"));
                                out = new PrintWriter("output.txt");
                        }
                        Locale.setDefault(Locale.US);
                        solve();
                        in.close();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = " + (t2 - t1));
                } catch (Throwable t) {
                        t.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        String readString() throws IOException {
                while (!tok.hasMoreTokens()) {
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException {
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException {
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException {
                return Double.parseDouble(readString());
        }

        // solution

       void generatePrime(int n) {

       }

       void solve() throws IOException {
           int n = readInt(), k = readInt();
           int count = 0;
           int[] f;
           boolean flag = true;
           boolean first = true;
           for (int i = 0; i < n; i++) {
               f = new int[k + 1];
               flag = true;
               int x = readInt();
               first = true;
               while(x != 0 || first) {
                   first = false;
                   int d = x%10;
                   x/=10;
                   if (d > k) {
                       flag = false;
                       break;
                   }
                   f[d]++;
               }
               for (int j = 0; j <= k; j++) {
                   flag &= f[j] > 0;
               }
               if (flag == true) {
                   count++;
               }
           }
           System.out.println(count);
       }

}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution implements Runnable {

        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        public static void main(String[] args) {
                new Thread(null, new Solution(), "", 256 * (1L << 20)).start();
        }

        public void run() {
                try {
                        long t1 = System.currentTimeMillis();
                        if (System.getProperty("ONLINE_JUDGE") != null) {
                                in = new BufferedReader(new InputStreamReader(System.in));
                                out = new PrintWriter(System.out);
                        } else {
                                in = new BufferedReader(new FileReader("input.txt"));
                                out = new PrintWriter("output.txt");
                        }
                        Locale.setDefault(Locale.US);
                        solve();
                        in.close();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = " + (t2 - t1));
                } catch (Throwable t) {
                        t.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        String readString() throws IOException {
                while (!tok.hasMoreTokens()) {
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException {
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException {
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException {
                return Double.parseDouble(readString());
        }

        // solution

       void generatePrime(int n) {

       }

       void solve() throws IOException {
           int n = readInt(), k = readInt();
           int count = 0;
           int[] f;
           boolean flag = true;
           boolean first = true;
           for (int i = 0; i < n; i++) {
               f = new int[k + 1];
               flag = true;
               int x = readInt();
               first = true;
               while(x != 0 || first) {
                   first = false;
                   int d = x%10;
                   x/=10;
                   if (d > k) {
                       continue;
                   }
                   f[d]++;
               }
               for (int j = 0; j <= k; j++) {
                   flag &= f[j] > 0;
               }
               if (flag == true) {
                   count++;
               }
           }
           System.out.println(count);
       }

}


import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;

public class Solution implements Runnable {

        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        public static void main(String[] args) {
                new Thread(null, new Solution(), "", 256 * (1L << 20)).start();
        }

        public void run() {
                try {
                        long t1 = System.currentTimeMillis();
                        if (System.getProperty("ONLINE_JUDGE") != null) {
                                in = new BufferedReader(new InputStreamReader(System.in));
                                out = new PrintWriter(System.out);
                        } else {
                                in = new BufferedReader(new FileReader("input.txt"));
                                out = new PrintWriter("output.txt");
                        }
                        Locale.setDefault(Locale.US);
                        solve();
                        in.close();
                        out.close();
                        long t2 = System.currentTimeMillis();
                        System.err.println("Time = " + (t2 - t1));
                } catch (Throwable t) {
                        t.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        String readString() throws IOException {
                while (!tok.hasMoreTokens()) {
                        tok = new StringTokenizer(in.readLine());
                }
                return tok.nextToken();
        }

        int readInt() throws IOException {
                return Integer.parseInt(readString());
        }

        long readLong() throws IOException {
                return Long.parseLong(readString());
        }

        double readDouble() throws IOException {
                return Double.parseDouble(readString());
        }

        // solution

       void generatePrime(int n) {

       }

       void solve() throws IOException {
           int n = readInt(), k = readInt();
           int count = 0;
           int[] f;
           boolean flag = true;
           for (int i = 0; i < n; i++) {
               f = new int[k + 1];
               flag = true;
               int x = readInt();
               while(x != 0) {
                   int d = x%10;
                   x/=10;
                   if (d > k) {
                       flag = false;
                       break;
                   }
                   f[d]++;
               }
               for (int j = 0; j <= k; j++) {
                   flag &= f[j] > 0;
               }
               if (flag == true) {
                   count++;
               }
           }
           System.out.println(count);
       }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class a {

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(in.readLine());
		int N = Integer.parseInt(st.nextToken()), K = Integer.parseInt(st.nextToken());
		int cont = 0;
		for(int i=0;i<N;++i){
			String num = in.readLine();
			boolean[] vis = new boolean[10];
			for(int j=0;j<num.length();++j){
				vis[num.charAt(j)-'0']=true;
			}
			boolean ws = true;
			for(int j=0;j<=K&&ws;++j)
				if(!vis[j])ws=false;
			cont += ws ?1:0;
		}
		System.out.println(cont);
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class a {

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(in.readLine());
		int N = Integer.parseInt(st.nextToken()), K = Integer.parseInt(st.nextToken());
		int cont = 0;
		for(int i=0;i<N;++i){
			String num = in.readLine();
			boolean[] vis = new boolean[10];
			for(int j=0;j<num.length();++j){
				vis[num.charAt(j)-'0']=true;
			}
			boolean ws = true;
			for(int j=0;j<K&&ws;++j)
				if(!vis[j])ws=false;
			cont += ws ?1:0;
		}
		System.out.println(cont);
	}

}


import java.util.Scanner;

public class A {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=0;
		while (n!=0) {
			String a=sc.next();
			int r=1;
			for (int i = 0; i <= k; i++) {
				if(a.contains(i+"")==false){r=0;break;}
			}
			if(r==1)res++;
			n--;

		}
		System.out.println(res);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class A {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=0;
		int v[]=new int[k+1];
		while (n!=0) {
			int a=sc.nextInt();
			while (a!=0) {
				int ai=a%10;
				if(ai<=k)v[ai]=1;
				a=a/10;
			}

			if(Arrays.binarySearch(v, 0)==-1) res++;
			n--;
			Arrays.fill(v, 0);
		}
		System.out.println(res);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class A {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=n;
		int v[]=new int[k+1];
		while (n!=0) {
			int a=sc.nextInt();
			while (a!=0) {
				int ai=a%10;
				if(ai<=k)v[ai]=1;
				a=a/10;
			}

			for (int i = 0; i < v.length; i++) {
				if(v[i]==0) {res--;break;}
			}
			n--;
			Arrays.fill(v, 0);

		}
		System.out.println(res);

	}

}


import java.util.Scanner;

public class A {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=0;
		while (n!=0) {
			String a=sc.next();
			int r=1;
			for (int i = 0; i <= k; i++) {
				if(a.contentEquals(i+"")==false){r=0;break;}
			}
			if(r==1)res++;
			n--;

		}
		System.out.println(res);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class A1 {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=0;
		while (n!=0) {

			n--;

		}
		System.out.println(res);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class A {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=0;
		int v[]=new int[k+1];
		while (n!=0) {
			int a=sc.nextInt();
			while (a!=0) {
				int ai=a%10;
				if(ai<=k)v[ai]=1;
				a=a/10;
			}

			if(Arrays.binarySearch(v, 0)==-1) res++;
			n--;
		}
		System.out.println(res);

	}

}


import java.util.Arrays;
import java.util.Scanner;

public class A {

	static Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		int n=sc.nextInt();

		int k=sc.nextInt();
		int res=0;
		int v[]=new int[k+1];
		while (n!=0) {
			int a=sc.nextInt();
			while (a!=0) {
				v[a%10]=1;
				a=a/10;
			}

			if(Arrays.binarySearch(v, 0)==-1) res++;
			n--;
		}
		System.out.println(res);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{

    public static void main(String[] args) {

        InputReader in = new InputReader(System.in);
        int t = in.nextInt();
        int k = in.nextInt();
        int cnt = t;
        for (int i = 0; i < t; i++) {
            long val = in.nextLong();
            String s = "" + val;
            for (int j = 0; j <= k; j++) {
                if (!s.contains("" + j)) {
                    cnt--;
                    break;
                }
            }
        }
        System.out.println(cnt);

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                return null;
            }
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.StringTokenizer;

/**
 *
 * @author baha
 */
public class KGood {

    static Scanner in;
    static Output out;

    public static void main(String[] args) throws Exception {
        boolean isFile = false;
        String filenameIn = null;
        if (isFile) {
            in = new Scanner(filenameIn);
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
        int n = in.nextInt();
        int k = in.nextInt();
        int counter = 0;
        for (int i = 0; i < n; i++) {
            String input = in.nextLine();
            boolean isGood = true;
            boolean exist[] = new boolean[10];
            for (int j = 0; j < input.length(); j++) {
                exist[Character.getNumericValue(input.charAt(j))] = true;
            }
            for (int j = 0; j <= k; j++) {
                if (!exist[j]) {
                    isGood = false;
                    break;
                }
            }
            if (isGood) {
                counter++;
            }
        }
        out.println(counter);
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader in;

        public Scanner() {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        public Scanner(String fileName) throws FileNotFoundException {
            in = new BufferedReader(new FileReader(fileName));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(in.readLine());
            }
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return in.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(out);
        }

        public Output(File file) throws FileNotFoundException {
            super(file);
        }
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		int y=input.nextInt();
		int jumlah=0;
		for(int j=0;j<n;j++)
		{
			String bil=new Scanner(System.in).nextLine();
			char[] temp=bil.toCharArray();
			boolean found=false;
			for(int i=0;i<=y;i++)
			{
				if(bil.indexOf(""+i)==-1)
				{
					found=true;break;
				}
			}
			if(!found)
			{
				jumlah++;
			}
		}
		System.out.println(jumlah);
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		Scanner input=new Scanner(System.in);
		BufferedReader scan=new BufferedReader(new InputStreamReader(System.in));
		int n=input.nextInt();
		int y=input.nextInt();
		int jumlah=0;
		int j=0;
		input.nextLine();
		while(n-- > 0){
				String bil=input.nextLine();
				char[] temp=bil.toCharArray();
				boolean found=false;
				for(int i=0;i<=y;i++)
				{
					if(bil.indexOf(""+i)==-1)
					{
						found=true;break;
					}
				}
				if(!found)
				{
					jumlah++;
				}
		}
		System.out.println(jumlah);
	}
}


import java.io.*;
import java.util.*;

public class A implements Runnable {

	private void solve() throws IOException {
		int n = nextInt(), k = nextInt(), cnt = 0;
		for (int i = 0; i < n; i++) {
			String s = nextToken();
			boolean[] used = new boolean[10];
			for (int j = 0; j < s.length(); j++)
				used[s.charAt(j) - '0'] = true;
			boolean ok = true;
			for (int j = 0; j <= k; j++)
				if (!used[j]) ok = false;
			if (ok) cnt++;
		}
		print(cnt);
	}

	public static void main(String[] args) {
		new A().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	void halt() {
		writer.close();
		System.exit(0);
	}

	void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	void println(Object... objects) {
		print(objects);
		writer.println();
	}

	String nextLine() throws IOException {
		return reader.readLine();
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(nextLine());
		return tokenizer.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.io.*;
import java.util.*;

public class A implements Runnable {

	private void solve() throws IOException {
		int n = nextInt(), k = nextInt(), cnt = 0;
		for (int i = 0; i < n; i++) {
			String s = nextToken();
			boolean ok = true;
			for (int j = 0; j < s.length(); j++)
				if (s.charAt(j) - '0' > k) ok = false;
			if (ok) cnt++;
		}
		print(cnt);
	}

	public static void main(String[] args) {
		new A().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			writer = new PrintWriter(System.out);
			solve();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(261);
		}
	}

	void halt() {
		writer.close();
		System.exit(0);
	}

	void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	void println(Object... objects) {
		print(objects);
		writer.println();
	}

	String nextLine() throws IOException {
		return reader.readLine();
	}

	String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens())
			tokenizer = new StringTokenizer(nextLine());
		return tokenizer.nextToken();
	}

	int nextInt() throws NumberFormatException, IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws NumberFormatException, IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextToken());
	}
}


import java.util.Scanner;

public class A {

    public static void main(String args[]) {

        Scanner s = new Scanner(System.in);
        Integer n = s.nextInt();
        Integer k = s.nextInt();

        int ans = 0;
        for (int i = 0; i < n; i++)
            if (isKGood(s.nextInt(), k))
                ans++;

        System.out.println(ans);

    }

    static boolean isKGood(int in, int k) {

        if (in == 0 && k == 0)
            return true;

        int a[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

        while (in > 0) {
            int m = in % 10;
            in = in / 10;

            a[m] = 1;
        }

        for (int i = 0; i <= k; i++)
            if (a[i] != 1)
                return false;

        return true;
    }

}


import java.util.Scanner;

public class A {

    public static void main(String args[]) {

        Scanner s = new Scanner(System.in);
        Integer n = s.nextInt();
        Integer k = s.nextInt();

        int ans = 0;
        for (int i = 0; i < n; i++)
            if (isKGood(s.nextInt(), k))
                ans++;

        System.out.println(ans);

    }

    static boolean isKGood(Integer in, int k) {

        if (in.equals(0) && k == 0)
            return true;

        int a[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

        while (in > 0) {
            int m = in % 10;
            in = in / 10;

            a[m] = 1;
        }

        for (int i = 0; i <= k; i++)
            if (a[i] != 1)
                return false;

        return true;
    }

}


import java.io.*;
public class GoodNumber {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try{

			BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
			PrintWriter p=new PrintWriter(System.out,true);

		while(reader.ready()){
				String []s=reader.readLine().split("\\s+");
				int n=Integer.parseInt(s[0]);
				int k=Integer.parseInt(s[1]);
				int num=0;boolean d=true;;
				String []a=new String[100];
				for(int i=0;i<n;i++){
					a[i]=reader.readLine();
				}

				for(int i=0;i<n;i++){
					d=true;
					for(int j=0;j<k;j++){

 					  if(!(a[i].substring(j,j+1).equals(String.valueOf(j+1)))){
						d=false;break;
					}

					}

					if(a[i].length()==(k+1)){
					 if(!(a[i].charAt(k)=='0')){
						  d=false;
					  }

					 }
					if(a[i].length()!=(k+1)){
						d=false;
					}

					if(d)
						++num;

				}

				System.out.println(num);

		}

		}
		catch(Exception e){
			e.printStackTrace();
		}

	}

}


import java.io.*;
public class GoodNumber {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try{

			BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
			PrintWriter p=new PrintWriter(System.out,true);

		while(reader.ready()){
				String []s=reader.readLine().split("\\s+");
				int n=Integer.parseInt(s[0]);
				int k=Integer.parseInt(s[1]);
				int num=0;boolean d=true;
				String []a=new String[100];

				for(int i=0;i<n;i++){
					d=true;
					a[i]=reader.readLine();
					boolean []f=new boolean[10];
					for(int j=0;j<=k;j++){
						if(a[i].contains(String.valueOf(j)))
							f[j]=true;
					}
					for(int j=0;j<=k;j++){
						if(f[j]==false){d=false;break;}
					}
					if(d)
						num++;

				}

			    p.println(num);

		}

		}
		catch(Exception e){
			e.printStackTrace();
		}

	}

}


import java.io.*;
public class GoodNumber {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try{

			BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
			PrintWriter p=new PrintWriter(System.out,true);

				String []s=reader.readLine().split("\\s+");
				int n=Integer.parseInt(s[0]);
				int k=Integer.parseInt(s[1]);
				int num=0;boolean d=true;;
				String []a=new String[100];
				for(int i=0;i<n;i++){
					a[i]=reader.readLine();
				}

				for(int i=0;i<n;i++){
					for(int j=0;j<k;j++){
					 int w=j+1;
 					  if(!(a[i].substring(j,j+1)==String.valueOf(w))){
						break;
					}

					}
					 if(!(a[i].charAt(k)=='0')){
						  continue;
					  }
					if(!d)
						continue;
					num++;

				}

				System.out.println(num);

		}
		catch(Exception e){
			e.printStackTrace();
		}

	}

}


import java.io.*;
public class GoodNumber {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try{

			BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
			PrintWriter p=new PrintWriter(System.out,true);

		while(reader.ready()){
				String []s=reader.readLine().split("\\s+");
				int n=Integer.parseInt(s[0]);
				int k=Integer.parseInt(s[1]);
				int num=0;boolean d=true;;
				String []a=new String[100];
				for(int i=0;i<n;i++){
					a[i]=reader.readLine();
				}

				for(int i=0;i<n;i++){
					d=true;
					for(int j=0;j<k;j++){

 					  if(!(a[i].substring(j,j+1).equals(String.valueOf(j+1)))){
						d=false;break;
					}

					}

					if(a[i].length()>=k+1){
					 if(!(a[i].contains("0"))){
						  d=false;
					  }
	             	}
					else
						d=false;

					if(d)
						++num;

				}

				System.out.println(num);

		}

		}
		catch(Exception e){
			e.printStackTrace();
		}

	}

}


import java.io.*;
public class GoodNumber {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		try{

			BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
			PrintWriter p=new PrintWriter(System.out,true);

				String []s=reader.readLine().split("\\s+");
				int n=Integer.parseInt(s[0]);
				int k=Integer.parseInt(s[1]);
				int num=0;boolean d=true;;
				String []a=new String[100];
				for(int i=0;i<n;i++){
					a[i]=reader.readLine();
				}

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

 					  if(!(a[i].substring(j,j+1).equals(String.valueOf(j+1)))){
						d=false;break;
					}

					}
					 if(!(a[i].charAt(k)=='0')){
						  d=false;
					  }
					if(d)
						num++;

				}

				System.out.println(num);

		}
		catch(Exception e){
			e.printStackTrace();
		}

	}

}


import java.util.*;
public class GoodNumber {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input=new Scanner(System.in);
		int n=input.nextInt();
		int k=input.nextInt();
		int c=0;
		boolean flag=true;
		String []a=new String[n];
		ArrayList<Integer>l=new ArrayList<Integer>();
		for(int i=0;i<=k;i++){
			l.add(i);
		}
		for(int i=0;i<a.length;i++){
			a[i]=input.next();
		}
		for(int i=0;i<a.length;i++){
			flag=true;
			for(int j=0;j<l.size();j++){
				if(!a[i].contains(l.get(j)+"")){
					flag=false;
					break;
				}
			}
			if(flag)
				c++;
		}
		System.out.println(c);
	}

}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int count = 0;
        co: for (int i = 0; i < n; i++) {
            String str = scan.next();
            boolean vis[] = new boolean[10000];
            for (int j = 0; j < str.length(); j++) {
                int term=str.charAt(j)-48;
                vis[term] = true;
            }
            for (int p = 0; p <= k; p++) {
                if (vis[p] == false)
                    continue co;
            }
            count++;
        }
        System.out.println(count);
    }
}