#include "testlib.h"
#include <vector>
#include <map>
#include <set>
#include <string>

using namespace std;


int main(int argc, char* argv[])
{
    registerValidation(argc, argv);
    
    int N = inf.readInt(1, 10000, "N");
    inf.readSpace();
    int M = inf.readInt(1, 10000, "M");
    inf.readEoln();
    for(int i = 0; i < M; ++i)
    {
        int Ki = inf.readInt(1, 10000, "Ki");
        inf.readSpace();
        for(int j = 0; j < Ki; ++j)
        {
            int Pij = inf.readInt(1, N, "Pij");
            if (j != Ki - 1) inf.readSpace();
            if (j == 0) ensuref(Pij == 1, "Wrong first junction");
        }
        inf.readEoln();
    }
    
    inf.readEof();
    return 0;
}