Problem:
When Can We Meet?
The ICPC committee would like to have its meeting as soon as
possible to address every little issue of the next contest.  
However, members of the committee are so busy maniacally developing
(possibly useless) programs that it is very difficult to arrange
their schedules for the meeting.
So, in order to settle the meeting date, the chairperson requested every
member to send back a list of convenient dates by E-mail.
Your mission is to help the chairperson, who is now dedicated to other
issues of the contest, by writing a program that 
chooses the best date from the submitted lists.
Your program should find the date convenient for the most members.
If there is more than one such day, the earliest is the best.
Input
The input has multiple data sets, each starting with a line
containing the number of committee members and the quorum of the meeting.
N Q
Here,
N
, meaning the size of the committee, and
Q
meaning the quorum, are positive integers.
N
is less than 50,
and, of course,
Q
is less than or equal to
N.
N
lines follow, each describing convenient dates for a
committee
member in the following format.
M Date
1
Date
2
...
Date
M
Here,
M
means the number of convenient dates for
the member, which is an integer greater than or equal to zero.
The remaining items in the line are his/her dates of convenience,
which are positive integers less than 100, that is, 1 means tomorrow, 
2 means the day after tomorrow, and so on.
They are in ascending order without any repetition 
and separated by a space character.
Lines have neither leading nor trailing spaces.
A line containing two zeros indicates the end of the input.
Output
For each data set, print a single line containing the date number
convenient for the largest number of committee members.
  If there is more than one
such date, print the earliest.  However, if no dates are convenient
for more than or equal to the quorum number of members, print 0 instead.
Sample Input
3 2
2 1 4
0
3 3 4 8
3 2
4 1 5 8 9
3 2 5 9
5 2 4 5 7 9
3 3
2 1 4
3 2 5 9
2 2 4
3 3
2 1 2
3 1 2 9
2 2 4
0 0
Output for the Sample Input
4
5
0
2

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
#define LL_INF 9223372036854775807
#define INT_INF 2147483647
using namespace std;
using ll = long long;

int main()
{
  int n, q, ans, hint;
  multiset<int> mst;
  while (true)
  {
    mst.clear();
    cin >> n >> q;
    if (n == 0 && q == 0)
    {
      return 0;
    }
    for (int i = 0; i < n; i++)
    {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++)
      {
        int a;
        cin >> a;
        mst.insert(a);
      }
    }
    hint = 0;
    ans = 0;
    for (int i = 0; i < 110; i++)
    {
      if (mst.count(i) > hint)
      {
        ans = i;
        hint = mst.count(i);
      }
    }
    if (hint < q)
    {
      ans = 0;
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 18

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<deque>
#include<cmath>
#include<functional>

#define rep(i,n) for(int i=0;i<n;i++)
#define derep(i,n) for(int i=n;i>=0;i--)
using namespace std;
typedef long long ll;
template<class T>void chmax (T&a,T b ){if(a<b)a=b;}
template<class T>void chmin (T&a, T b){if(a>b)a=b;}

const int dx[]={1,0,-1,0,1,-1,1,-1};
const int dy[]={0,1,0,-1,1,-1,-1,1};
const int INF=1<<25;
const ll inf=1LL<<60;
const int mod=1000000007 ;
const int arx=1000,ary=1000;
using graph=vector<vector<ll>>;
struct unionfind{
 vector<int>par;
 unionfind(int n):par(n){
  rep(i,n)par[i]=i;
 }
  int  root(int x){
   if(par[x]==x)return x;
   else return par[x]=root(par[x]);
  }
  void unit(int x,int y){
    int rx=root(x);
    int ry=root(y);
     
   if(rx==ry)return ;
   else par[rx]=ry;
  }
   bool same(int x,int y){
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
    } 
}; 

int main(){
while(1){
int n,q;
cin>>n>>q;
 if(n==0&&q==0)return 0;
 map<int,ll>mp;
map<int,bool>cp;
int large=-1,ite; 
rep(i,n){
int m;
cin>>m;
 cp.clear();
 rep(i,m){
  int y;
cin>>y;
 if(!cp[y]){
  mp[y]++;
   cp[y]=true;
if(large<mp[y]||ite>y&&large==mp[y]){
ite=y;
large=mp[y];
 }
}


   }

     }
     
      if(large<q)cout<<0<<endl;
    else cout<<ite<<endl;
 
}
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)

void solve()
{
    int n, q;
    while (cin >> n >> q)
    {
        if (n == 0)
            break;
        vector<map<int, int>> a(n);
        REP(i, n)
        {
            int m;
            cin >> m;
            REP(j, m)
            {
                int tmp;
                cin >> tmp;
                a[i][tmp] = 1;
            }
        }
        int c = 0, d = 0;
        rep(i, 1, 101)
        {
            int cnt = 0;
            REP(j, n)
            {
                if (a[j][i] == 1)
                    cnt++;
            }
            if (cnt >= q && cnt > c)
            {
                c = cnt;
                d = i;
            }
        }
        cout << d << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3376
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int, int>
#define us unordered_set
#define ud unordered_dict
#define Lower_bound(vec, n) distance((vec).begin(), lower_bound((vec).begin(), (vec).end(), (n)))
#define Upper_bound(vec, n) distance((vec).begin(), upper_bound((vec).begin(), (vec).end(), (n)))
#define Erase(vec) (vec).erase(unique((vec).begin(), (vec).end()), (vec).end())
//template <class T = int> in()(T x; cin >> x; return (x);)
//template <class T> print(T& x) (cout << x << endl;)
//using template <class T> vec = vector<T>;
using Graph = vector<vector<int>>;
const int INF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

signed main() {
    int N, Q;
    while (true) {
        cin >> N >> Q;
        if (N == 0) break;

        vi days;
        int day_num;
        int intmp;
        REP(i, N) {
            cin >> day_num;
            REP(j, day_num) {
                cin >> intmp;
                days.push_back(intmp);
            }
        }

        int best = 0;
        int best_people = 0;
        FOR(i, 1, 100) {
            int i_num = count(ALL(days), i);
            if (i_num >= Q && i_num > best_people) {
                best_people = i_num;
                best = i;
            }
        }
        
        cout << best << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3360
final_rank: 17

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD 1000000007
#define PI 3.14159265358979323846264338327950288419

#define int long long
#define ll long long
#define pint pair<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define pff first.first
#define pfs first.second
#define psf second.first
#define pss second.second

const ll ll_max = LLONG_MAX;
#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divceil(a, b) (((a) + ((b) - 1)) / (b))
#define outyn(flag) cout << ((flag)? "Yes": "No") << endl
#define outYN(flag) cout << ((flag)? "YES": "NO") << endl
#define out(output) cout << (output) << endl

template <typename T>
void chmax(T &a, T b){
    if(a < b) a = b;
}

int N, Q;

void solve(){

    int M, d;
    map<int, int> mp;
    for(int i = 0; i < N; i++){
        cin >> M;
        for(int j = 0; j < M; j++){
            cin >> d;
            mp[d]++;
        }
    }

    //50-人数,date
    set<pair<int, int>> st;
    for(auto itr = mp.begin(); itr != mp.end(); itr++){
        st.insert(mpair(50-itr->second, itr->first));
    }

    auto stfirst = st.begin();
    if(stfirst == st.end()) cout << 0 << endl;
    else if(50-stfirst->first < Q) cout << 0 << endl;
    else cout << stfirst->second << endl;

}

#undef int
int main(){

    //solve();

    while(true){
        cin >> N >> Q;
        if(N == 0 && Q == 0) break;

        solve();
    }
    
    /*int numOfInput;
    cin >> numOfInput;
    for(int i = 0; i < numOfInput; i++){
        solve();
    }*/

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3336
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
typedef tuple< ll, ll, ll > Tp;
using vl = vector<ll>;
using vs = vector<string>;
using vvl = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
#define mt make_tuple
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

void Main(ll N,ll Q){
    map<ll,ll>m;
    ll mx=0,ans;
    rep(i,N){
        ll M;
        cin>>M;
        rep(j,M){
            ll d;
            cin>>d;
            m[d]++;
            if(m[d]>mx){
                mx=m[d];
                ans=d;
            }else if(m[d]==mx&&d<ans){
                ans=d;
            }
        }
    }
    if(mx<Q){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
    }
}

int main() {
    
    while(1){
        ll N,Q;
        cin>>N>>Q;
        if((N|Q)==0)break;
        Main(N,Q);
    }

    return 0;
    

}
accuracy: 1
time_ms: 10
memory_kb: 3156
final_rank: 13

code_snippet: #include<iostream>
#include<fstream>
#include<bitset>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>
#include<climits>
#include<ctime>
#include<functional>

using namespace std;

#define int long long
#define rep(i,n) for(LL i=0;i<(n);i++)
#define rep1(i,n) for(LL i=1;i<(n);i++)
#define rrep(i,n) for(LL i=(n)-1;i>=0;i--)
#define all(a) (a).begin(),(a).end()
#define check() cout<<"! ! !"<<endl
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl


constexpr long double PI = 3.141592653589793238;
constexpr long long INF = (long long)1e15;
constexpr long long MOD = 1e9 + 7;


using LL = long long;
using st = string;
template<typename T>using vec = vector<T>;
template<typename T>using vvec = vec<vec<T>>;
template<typename T>using vvvec = vec<vvec<T>>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using pi = pair<int, int>;
using ppi = pair<pi, int>;
using vpi = vector<pi>;
using vppi = vector<ppi>;
using mii = map<int, int>;
using mpii = map<pi, int>;
using mib = map<int, bool>;
using mci = map<char, int>;
template<typename T>using pq_greater = priority_queue<T>;
template<typename T>using pq_smaller = priority_queue<T, vec<T>, greater<T>>;


//4,2,8,6,1,7,3,9,5 (x:right y:up is positive)
int dx[] = { -1,0,0,1,-1,-1,1,1,0 };
int dy[] = { 0,1,-1,0,1,-1,1,-1,0 };

template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
	rep(i, v.size()) {
		in >> v[i];
	}
	return in;
}

template<typename T, typename U>
istream &operator>>(istream&in, pair<T, U> &p) {

	in >> p.first >> p.second;
	return in;
}

template<typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
	out << "{";
	rep(i, v.size()) {
		out << v[i] << ",";
	}
	out << "}" << endl;

	return out;
}

template<typename T, typename U>
ostream &operator<<(ostream&out, pair<T, U> &p) {

	out << "{" << p.first << "," << p.second << "}" << endl;
	return out;
}

struct mint {
	int x;
	mint(int x = 0) :x((x%MOD + MOD) % MOD) {}

	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(int t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& out, const mint& m) {
		out << m.x;
		return out;
	}

};

void y_n(bool p) {
	p ? _y() : _n();
}

void Y_N(bool p) {
	p ? _Y() : _N();
}

bool endInput(vi a) {
	for (auto i : a) {
		if (i != 0)return false;
	}
	return true;
}

//MAX,maxpos,MIN,minpos
template<typename T>
pair<pair<T, int>, pair<T, int>> vmaxmin(vector<T> v) {
	int MAX = -INF;
	int MIN = INF;
	int maxpos = 0;
	int minpos = 0;
	rep(i, v.size()) {
		if (MAX < v[i]) {
			maxpos = i;
			MAX = v[i];
		}
		if (MIN > v[i]) {
			minpos = i;
			MIN = v[i];
		}
	}
	return { {MAX,maxpos},{MIN,minpos} };
}

template<typename T>
T vsum(vector<T> v) {
	T sum = 0;
	rep(i, v.size()) {
		sum += v[i];
	}
	return sum;
}

int gcd(int a, int b) {
	if (b == 0) {
		swap(a, b);
	}
	int r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

int lcm(int a, int b) {
	return (a / gcd(a, b) * b);
}

bool is_square(int n) {
	if ((int)sqrt(n)*(int)sqrt(n) == n) {
		return true;
	}
	else {
		return false;
	}
}


bool is_prime(int n) {
	if (n <= 1) {
		return false;
	}
	else {
		for (int i = 2; i*i <= n; i++) {
			if (n % i == 0) {
				return false;
			}
		}
	}
	return true;
}

void dec_num(int n, vi &v) {
	int a = 2;
	v.push_back(1);
	v.push_back(n);
	while (a*a <= n) {
		if (n%a == 0) {
			v.push_back(a);
			v.push_back(n / a);
		}
		a++;
	}
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}


void dec_prime(int n, vi &v) {
	//v.push_back(1);
	int a = 2;
	while (a*a <= n) {
		if (n % a == 0) {
			v.push_back(a);
			n /= a;
		}
		else {
			a++;
		}
	}
	v.push_back(n);
}

//n= ...*pow(p_i,m[p_i])*...
void dec_prime_e(int n, map<int, int> &m) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			int e = 0;
			while (n%i == 0) {
				e++;
				n /= i;
			}
			m[i] += e;
		}
	}
	if (n != 1) m[n]++;
}


int sieve_prime(int a, int b) {
	if (a > b)swap(a, b);
	vb s(b + 1, true);
	int cnt_a = 0, cnt_b = 0;
	for (int i = 2; i <= b; i++) {
		for (int j = 2; i*j <= b; j++) {
			s[i*j] = false;
		}
	}
	//return s;
	for (int i = 2; i <= b; i++) {
		if (s[i]) {
			//cout << i << " ";
			if (i < a) {
				cnt_a++;
			}
			cnt_b++;
		}
	}
	return cnt_b - cnt_a;

}


int factorial(int n) {
	int a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= MOD;
	}
	return ret;
}

int bit_count(int n) {
	int k = (int)log2(n) + 1;
	int ret = 0;
	rep(i, k) {
		if (n&(1LL << i))ret++;
	}
	return ret;
}

//a^(a+1)^(a+2)^...^b
int XOR(int a, int b) {
	if (a == 0) {
		switch (b % 4) {
		case 0:	return b;
		case 1:	return 1;
		case 2:	return (b + 1);
		case 3:	return 0;
		}
	}
	int A = XOR(0, a - 1);
	int B = XOR(0, b);
	return (A ^ B);
}


const int COMBMAX = 4000;
int comb[COMBMAX + 5][COMBMAX + 5];

void init_comb() {
	comb[0][0] = 1;
	rep(i, COMBMAX) {
		rep(j, i + 1) {
			comb[i + 1][j] += comb[i][j];
			//comb[i + 1][j] %= MOD;
			comb[i + 1][j + 1] += comb[i][j];
			//comb[i + 1][j + 1] %= MOD;
		}
	}
}

int combination(int n, int k) {
	if (k<0 || k>n)return 0;
	else return comb[n][k];
}


const int COMBMODMAX = 5000000;
int fac[COMBMODMAX + 5], facinv[COMBMODMAX + 5], inv[COMBMODMAX + 5];

void init_comb_mod() {
	fac[0] = fac[1] = 1;
	facinv[0] = facinv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < COMBMODMAX; i++) {
		fac[i] = fac[i - 1] * i%MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		facinv[i] = facinv[i - 1] * inv[i] % MOD;
	}
}

//nCk (mod p)
//nHk = n+k-1Ck
int comb_mod(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (facinv[k] * facinv[n - k] % MOD) % MOD;
}

//x^n (mod p)
int pow_mod(int x, int n, int p) {
	if (n == 0)return 1;
	int res = pow_mod(x*x%p, n / 2, p);
	if (n % 2 == 1)res = res * x % p;
	return res;
}

struct edge {
	int to;
	int cost;
};


using ve = vector<edge>;
using vve = vector<ve>;


/*****************************************************************************/




signed main() {

	while (1) {
		int n, q;
		cin >> n >> q;
		if (endInput(vi(n,q)))break;
		
		vvi a(n);
		mii cnt;
		rep(i, n) {
			int k;
			cin >> k;
			a[i].resize(k);
			cin >> a[i];
		}
		rep(i, n) {
			rep(j, a[i].size()) {
				cnt[a[i][j]]++;
			}
		}

		int ans = -1;
		int per = 0;
		rep(i, 110) {
			if (cnt[i]>=q&&per < cnt[i]) {
				ans = i;
				per = cnt[i];
			}
		}
		if (ans == -1) {
			cout << 0 << endl;
		}
		else {
			cout << ans << endl;
		}
	}

}
accuracy: 1
time_ms: 10
memory_kb: 3132
final_rank: 10

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

#define int long long

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif

#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9 + 7;


signed main(){

    while(1) {
        int n, q;
        cin >> n >> q;
        if(n==0&&q==0) break;
        vector<vector<int>> vv(n);
        for(int i=0; i<n; i++) {
            int m;
            cin >> m;
            vector<int> u(m);
            for(int j=0; j<m; j++) cin >> u[j];
            vv[i] = u;
        }

        map<int,int> mp;
        for(int i=0; i<n; i++){
            for(int j=0; j<vv[i].size(); j++){
                mp[vv[i][j]]++;
            }
        }

        int ans = 0;
        int mx = 0;
        for(auto itr = mp.begin(); itr != mp.end(); itr++) {
            debug((*itr).first, (*itr).second);
            if (mx < (*itr).second) {
                mx = (*itr).second;
                ans = (*itr).first;
            }
        }
        cout << (mx>=q?ans:0) << endl;
    }


}
accuracy: 1
time_ms: 10
memory_kb: 3192
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n, q;

int main() {
    while(1) {
        cin >> n >> q;
        if(n == 0 && q == 0) break;
        map<int, int> mcnt;
        for(int i = 0; i < n; ++i) {
            int m; cin >> m;
            for(int j = 0; j < m; ++j) {
                int ch; cin >> ch; mcnt[ch]++;
            }
        }
        int now = 0;
        int date = 0;
        for(auto x : mcnt) {
            if(q <= x.second) {
                if(now < x.second) {
                    now = x.second;
                    date = x.first;
                }
            }
        }
        cout << date << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3116
final_rank: 8

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    ll n,q;
    while(true){
        cin>>n>>q;
        if(n==0&&q==0)break;
        map<int,int>ma;
        for(int i=0;i<n;i++){
            int m;
            cin>>m;
            for(int j=0;j<m;j++){
                int d;
                cin>>d;
                ma[d]++;
            }
        }
        int ans1=0,ans2=0;
        for(auto itr=ma.begin();itr!=ma.end();++itr){
            int x=itr->second;
            if(x>=q){
                if(x>ans2){
                    ans1=itr->first;
                    ans2=x;
                }
            }
        }
        cout<<ans1<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3012
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n, q; cin >> n >> q;
    if(n == 0 && q == 0) break;
    map<int, int> mp;
    for(int i=0;i<n;++i) {
      int m; cin >> m;
      for(int j=0;j<m;++j) {
        int tmp; cin >> tmp;
        mp[tmp]++;
      }
    }

    int ans = 0;
    int ma = 0;
    for(const auto &i: mp) {
      if(i.second > ma) {
        ans = i.first;
        ma = i.second;
      }
    }
    if(ma < q) {
      cout << 0 << endl;
    } else {
      cout << ans << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 3020
final_rank: 3

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

int main(int argc, char const *argv[])
{
	int n,q;
	while(cin>>n>>q,n)
	{
		vector<int> v[n];
		int m,t,mi=1000000,ma=-1;
		for (int i = 0; i < n; ++i)
		{
			cin>>m;
			for (int j = 0; j < m; ++j) cin>>t,v[i].push_back(t),mi=min(mi,t),ma=max(ma,t);
		}
		int ans=-1,d=-1;
		for (int i = mi; i <= ma; ++i)
		{
			int k=0;
			for (int j = 0; j < n; ++j)
			{
				for (int l = 0; l < v[j].size(); ++l)
				{
					if(v[j].at(l)==i)
					{
						++k;
						break;
					}
				}
			}
			if(k>d) ans=i,d=k;
		}
		if(d>=q) cout<<ans<<endl;
		else cout<<"0\n";
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3156
final_rank: 13

code_snippet: #include<bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  int n,q;
  while(cin>>n>>q,n){
    int hai[100000]={};
    for(int i=0;i<n;i++){
      int m;cin>>m;
      for(int i=0;i<m;i++){
	int num;cin>>num;
	hai[num]++;
      }
    }
    int ans=0;
    bool flag=true;
    int anss=0;
    for(int i=1;i<100000;i++){
      if(hai[i]>=q){
	if(ans<hai[i]){
	  ans=max(ans,hai[i]);
	  anss=i;
	}
      }
    }
    cout<<anss<<endl;
    //if(flag)cout<<0<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3464
final_rank: 19

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N, Q;
	while(cin >> N >> Q && N+Q){
		map<int32, int32> cnt;
		REP(i, N){
			int32 M;
			cin >> M;
			REP(j, M){
				int32 x;
				cin >> x;
				cnt[x]++;
			}
		}
		int32 res = 0;
		for(auto x : cnt){
			if(x.sc >= Q && cnt[res] < x.sc){
				res = x.fs;
			}
		}
		cout << res << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3116
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

map<int,int> t;
int main(){
    int n,q,m,dt;
    while(cin>>n>>q,n){
        t.clear();
        rep(i,n){
            cin>>m;
            rep(j,m){
                cin>>dt;
                ++t[dt];
            }
        }
        int mx=-1,ans;
        for(auto it:t){
            if(mx<it.second) mx=it.second,ans=it.first;
        }
        cout<<(mx>=q?ans:0)<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3144
final_rank: 11

code_snippet: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

signed main(){
  int n,q;
  while(cin>>n>>q,n){
    map<int,int> mp;
    REP(i,n){
      int m;
      cin>>m;
      REP(j,m){
        int a;
        cin>>a;
        mp[a]++;
      }
    }
    int maxi=0;
    int ans=INF;
    for(auto x:mp){
      if(x.SC>maxi){
        maxi=x.SC;
        ans=x.FR;
      }else if(x.SC==maxi){
        ans=min(ans,x.FR);
      }
    }
    cout<<(maxi>=q?ans:0)<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3020
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

int main(){
    int n,q;
    while(cin >> n && n != 0){
        cin >> q;
        map<int,int> d;
        for(int i = 0;i < n; i++){
            int m; cin >> m;
            for(int j = 0; j < m; j++){
                int t; cin >> t;
                if(d.find(t) != d.end()){
                    d[t]++;
                }
                else{
                    d[t] = 1;
                }
            }
        }
        int ans = 0, num = 0;
        for(map<int,int>::iterator it = d.begin(); it != d.end(); it++){
            if(it->second > num){
                ans = it->first;
                num = it->second;
            }
        }
        if(num < q){
            cout << 0 << endl;
        }
        else cout << ans << endl;
    }

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 2988
final_rank: 1

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

void solve(int n,int q){
    int a,b;
    vector<int> v(100,0);
    for(int i=0;i<n;i++){
        cin >> a;
        for(int j=0;j<a;j++){
            cin >> b;
            v[b-1]++;
        }
    }
    int ans=0;
    ans=*max_element(v.begin(),v.end());
    cout<<((ans>=q)?(max_element(v.begin(),v.end())-v.begin()+1):0)<<endl;
    
}

int main(void){
    int a,b;
    while(cin>>a>>b,a){
        solve(a,b);
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3080
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int n,m;
    while(cin>>n>>m,n){
        vi d(101,0);
        int mx=-1;
        rep(i,n){
            int p,q; cin>>p;
            rep(j,p){
                cin>>q; d[q]++;
                mx=max(mx,d[q]);
            }
        }
        cout<<(mx<m?0:(find(all(d),mx)-d.begin()))<<endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3020
final_rank: 3

code_snippet: //#define _GRIBCXX_DEBUG
#include <bits/stdc++.h>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int n, q, m, d;
  map<int, int>::iterator it;

  while (cin >> n >> q, n) {
    map<int, int> freq;
    rep (i, n) {

      cin >> m;
      rep (k, m) {
        cin >> d;

        it = freq.find(d);
        if (it == freq.end()) {
          freq[d] = 1;
        }
        else {
          freq[d]++;
        }
      }
    }

    int max_d = -1;
    int max_v = 0;

    for (pair<int, int> p : freq) {
      if (max_v < p.second) {
        max_d = p.first;
        max_v = p.second;
      }
    }

    if (max_v >= q) {
      cout << max_d << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3096
final_rank: 7