#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> maze(10, vector<int>(10));
  vector<int> p(m);
  for (int i = 0; i < (int)(m); i++) {
    int k;
    cin >> k;
    for (int j = 0; j < (int)(k); j++) {
      cin >> maze[i][j];
    }
  }
  for (int i = 0; i < (int)(m); i++) {
    cin >> p[i];
  }
  for (int bit = 0; bit < (1 << n); ++bit) {
    vector<int> S;
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    }
    for (int i = 0; i < (int)S.size(); ++i) {
      cout << S[i] << " ";
    }
  }
}
