#include <cstdio>
#include <vector>
#include <algorithm>

#define MOD (1000000007)
#define EPS (1e-9)
#define INF (2117117117)
#define LLINF (2117117117117117117LL)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define sqr(a) ((a) * (a))
#define sz(a) ((int) (a).size())

typedef unsigned int uint;
typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

using namespace std;

#include "grader.h"

const int N = 20;

inline int popcount(unsigned int a)
{
    int res;
    for (res = 0; a; res += (a & 1), a >>= 1);
    return res;
}

vector<pair<int, pair<int, int> > > resmem;
int my_compare(int i, int j)
{
    resmem.pb(mp(compare(i, j), mp(i, j)));
    return resmem.back().first;
}

int identify_set(int n, int k, llong **sets)
{
    srand((n ^ k) + sets[0][0] % 10);
    vector<int> candidates;
    for (int cur = 0; cur < k; cur++)
    {
        bool f = true;
        for (auto &pr : resmem)
        {
            llong sum = 0;
            for (int i = 0; i < n; i++)
            {
                if ((pr.second.first >> i) & 1)
                    sum += sets[cur][i];
                if ((pr.second.second >> i) & 1)
                    sum -= sets[cur][i];
            }
            sum = (sum == 0 ? 0 : (sum < 0 ? -1 : 1));
            if (sum != pr.first)
            {
                f = false;
                break;
            }
        }
        if (!f)
            continue;
        for (int _ = 0; _ < N; _++)
        {
            int i, j;
            do
            {
                i = rand() % (1 << n);
                j = rand() % (1 << n);
            }
            while ((i & j) != 0);
            llong sum = 0;
            for (int t = 0; t < n; t++)
            {
                if ((i >> t) & 1)
                    sum += sets[cur][t];
                if ((j >> t) & 1)
                    sum -= sets[cur][t];
            }
            sum = (sum == 0 ? 0 : (sum < 0 ? -1 : 1));
            int res = my_compare(i, j);
            if (sum != res)
            {
                f = false;
                break;
            }
        }
        if (f)
            candidates.pb(cur);
    }
    return (sz(candidates) == 1 ? candidates[0] : -1);
}
