#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
  return x < y ? (x = y, 1) : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
  return x > y ? (x = y, 1) : 0;
}
const int N = 5e5 + 1, MOD = 1e9 + 7;
int n, m, vis[N], v[N], pk[N];
std::vector<int> edge[N], a[N], b[N];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x;
    while (x--) {
      cin >> y;
      a[i].push_back(y);
      b[y].push_back(i);
    }
  }
  for (int i = 1; i <= m; i++)
    if (b[i].size()) {
      int x = b[i][0], y = b[i].back();
      if (x != y) edge[x].push_back(y), edge[y].push_back(x);
    }
  for (int i = 1; i <= n; i++) sort(edge[i].begin(), edge[i].end());
  long long ans = 1;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) {
      int cur = i, ma = 0;
      set<int> tmp;
      while (!vis[cur]) {
        vis[cur] = 1;
        chkmax(ma, cur);
        for (auto j : a[cur])
          if (tmp.count(j))
            tmp.erase(j);
          else
            tmp.insert(j);
        if (tmp.empty()) {
          pk[ma] = 1;
          break;
        }
        ans = ans * 2 % MOD;
        for (auto j : edge[cur])
          if (!vis[j]) {
            cur = j;
            break;
          }
      }
    }
  cout << ans << ' ';
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (!pk[i]) cnt++;
  cout << cnt << '\n';
  for (int i = 1; i <= n; i++)
    if (!pk[i]) cout << i << ' ';
  cout << '\n';
  return 0;
}
