#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define nl '\n'
#define INF 1e9 + 5
#define f(i, n) for (int i = 0; i < n; ++i)

using namespace std;
pair<int, int> get(vector<int>& a, bool even, int skip) {
    int n = a.size();
    unordered_map<int, int> book;
    pair<int, int> res = {0, 0};
    if (even) {
        for (int i = 0; i < n; ++i) {
            if (i & 1 || a[i] == skip) continue;
            if (book.count(a[i]))
                book[a[i]]++;
            else
                book[a[i]] = 1;
            if (res.second < book[a[i]]) {
                res.first = a[i];
                res.second = book[a[i]];
            }
        }
    } else {
        for (int i = 0; i < n; ++i) {
            if (!(i & 1) || a[i] == skip) continue;
            if (book.count(a[i]))
                book[a[i]]++;
            else
                book[a[i]] = 1;
            if (res.second < book[a[i]]) {
                res.first = a[i];
                res.second = book[a[i]];
            }
        }
    }
    return res;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    f(i, n) cin >> a[i];
    int m = n / 2;
    pair<int, int> one = get(a, true, INF);
    pair<int, int> two = get(a, false, one.first);
    pair<int, int> three = get(a, false, INF);
    pair<int, int> four = get(a, true, one.first);
    int ans = min({(m - one.second) + (m - two.second),
                   (m - three.second) + (m - four.second)});
    cout << ans << nl;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}
#include<iostream>
using namespace std;

int m[101];

int main(){
  int n,q;
  int i,j;
  int d,x;
  int max,a,f;
  
  while(1){
    f=0;
    max=-1;
    for(i=0;i<101;i++){
      m[i]=0;
    }
    cin >> n >> q;
    if(n==0 && q==0)break;
    q--;
    for(i=0;i<n;i++){
      cin >> d;
      if(d==0)f=1;
      for(j=0;j<d;j++){
	cin >> x;
	m[x]++;
      }
    }
    a=0;
    for(i=0;i<100;i++){
      if(q<m[i]){
	q=m[i];
	a=i;
      }
      m[i]=0;
    }
    cout << a << endl;
  }
}