import bisect
import collections
import copy
import fractions
import functools
import heapq
import math
import random
import sys


def _p(str):
    sys.stdout.write(str+'\n')
def _i():
    return sys.stdin.readline()

if __name__ == '__main__':

    N, M = tuple(map(int, _i().split()))
    S = []
    for n in range(N):
        S.append(list(map(int, _i().split())))

    one_cnts = [0 for m in range(M)]
    cnts_to_index = {0: set(m for m in range(M))}

    S_prime = []
    for i, vector in enumerate(S):
        add = False
        if i == 0 or i == 1:
            add = True
        elif one_cnts[vector[1]-1] == 0:
            add = True
        elif vector[0] == 2 and one_cnts[vector[2]-1] == 0:
            add = True
        elif any(ind != vector[1]-1 and (vector[0] == 1 or ind != vector[2]-1) for ind in cnts_to_index[len(S_prime)]):
            add = True

        if add:
            S_prime.append(i)
            cnts_to_index[len(S_prime)] = set()

            cnts_to_index[one_cnts[vector[1]-1]].discard(vector[1]-1)
            one_cnts[vector[1]-1] += 1
            cnts_to_index[one_cnts[vector[1]-1]].add(vector[1]-1)

            if vector[0] == 2:
                cnts_to_index[one_cnts[vector[2]-1]].discard(vector[2]-1)
                one_cnts[vector[2]-1] += 1
                cnts_to_index[one_cnts[vector[2]-1]].add(vector[2]-1)

    for i in range(len(S_prime)-1, -1, -1):
        vector = S[S_prime[i]]
        if (
            one_cnts[vector[1]-1] > 1 and
            (vector[0] == 1 or one_cnts[vector[2]-1] > 1) and
            all(ind == vector[1]-1 or (vector[0] == 2 and ind == vector[2]-1) for ind in cnts_to_index[len(S_prime)-1])
        ):
            S_prime[i] = -1
            cnts_to_index[one_cnts[vector[1]-1]].discard(vector[1]-1)
            one_cnts[vector[1]-1] -= 1
            cnts_to_index[one_cnts[vector[1]-1]].add(vector[1]-1)

            if vector[0] == 2:
                cnts_to_index[one_cnts[vector[2]-1]].discard(vector[2]-1)
                one_cnts[vector[2]-1] -= 1
                cnts_to_index[one_cnts[vector[2]-1]].add(vector[2]-1)

    S_prime = list(filter(lambda x: x != -1, S_prime))

    diff_pos = sum([len(cnts_to_index[n]) for n in range(1, len(S_prime))])
    for ind in S_prime:
        vector = S[ind]
        if vector[0] == 2 and one_cnts[vector[1]-1] == 1 and one_cnts[vector[2]-1] == 1:
            diff_pos -= 1

    _p(str(2**diff_pos) + ' ' + str(len(S_prime)))
    _p(' '.join(map(lambda x: str(x+1), S_prime)))

    sys.stdout.flush()
