#include using namespace std; int n, k, a [850][850]; struct eee{ string str1, str2; }; eee z [850]; int main (){ ifstream fin ("hub.in"); ofstream fout ("hub.out"); fin >> n >> k; int qqq = n*(n-1)/2; for (int i = 0; i < qqq; i ++){ int u, v; fin >> u, v; a [u][v] = 1; } for (int i = 0; i < n; i ++) a [i][i] = 1; for (int i = 0; i < n; i ++){ string str1 = "", str2 = ""; for (int j = 0; j < n; j ++){ if (a [i][j] == 1) str1 += char (j); else str2 += char (j); } z[i].str1 = str1; z[i].str2 = str2; } for (int i = 0; i < k; i ++){ int p; fin >> p; string s = ""; for (int j = 0; j < p; j ++){ int q; fin >> q; s += char (q); } sort (s.begin(), s.end ()); int j; for (j = 0; j < n; j ++){ if (s == z [j].str1 || s == z [j].str2){ fout << j << endl; break; } } if (j == n) fout << -1 << endl; } return 0; }