#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 MAXN = 540000;

int res[MAXN], resn;

inline int my_compare(int i, int j, llong *sets, int n)
{
    llong sum = 0;
    for (int t = 0; t < n; t++)
    {
        if ((i >> t) & 1)
            sum += sets[t];
        if ((j >> t) & 1)
            sum -= sets[t];
    }
    return (sum == 0 ? 0 : (sum < 0 ? -1 : 1));
}

int identify_set(int n, int k, llong **sets)
{
    if (k == 1)
        return 0;
    if (n == 1)
        return -1;

    resn = 0;
    for (int i = 0; i < (1 << n); i++)
    {
        for (int j = i; j; j = ((j - 1) & i))
            res[resn++] = compare(j, j ^ i);
        res[resn++] = compare(0, i);
    }

    vector<int> candidates;
    for (int t = 0; t < k; t++)
    {
        bool f = true;
        int cur = 0;
        for (int i = 0; i < (1 << n); i++)
        {
            for (int j = i; j; j = ((j - 1) & i))
                f &= (res[cur++] == my_compare(j, j ^ i, sets[t], n));
            f &= (res[cur++] == my_compare(0, i, sets[t], n));
        }
        if (f)
            candidates.pb(t);
    }
    return (sz(candidates) == 1 ? candidates[0] : -1);
}
