#include <bits/stdc++.h>
int main() {
  int a, i, j, N, M;
  scanf("%d %d", &N, &M);
  printf("%d %d\n", N, M);
  int k[M], ans[M];
  for (i = 0; i < M; i++) {
    scanf("%d", &k[i]);
    printf("%d ", k[i]);
    a = k[i];
    int tmp = 0, s[a];
    for (j = 0; j < a; j++) {
      scanf("%d", &s[j]);
      printf("%d ", s[j]);
      if (s[j] == 2) tmp++;
      ans[i] = tmp % 2;
    }
    printf("\n");
  }
  int p[M], A = 0;
  for (i = 0; i < M; i++) {
    scanf("%d", &p[i]);
    printf("%d ", p[i]);
    if (p[i] == ans[i]) A++;
  }
  printf("\n");
  printf("%d", A);
}
