#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010, inf = 1e9, mod = 1e9 + 7;
struct edge {
  int too, xj, tooj, pre;
} e[maxn];
int n, m, top, tot, ans, tott;
int last[maxn], ed[maxn], cnt[maxn], a[maxn][2], pos[maxn], posj[maxn],
    f[maxn][2][2], deg[maxn], st[maxn], g[maxn][2], dp[maxn][2];
bool v[maxn];
template <typename T>
inline void read(T &k) {
  int f = 1;
  k = 0;
  char c = getchar();
  while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
  while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
  k *= f;
}
inline void add(int x, int y, int xj, int yj) {
  e[++tot] = (edge){y, xj, yj, last[x]};
  last[x] = tot;
}
void dfs(int x, int fa) {
  v[x] = 1;
  st[++top] = x;
  for (int i = last[x], too; i; i = e[i].pre)
    if (!v[too = e[i].too]) {
      ed[top] = a[x][e[i].xj] != a[too][e[i].tooj];
      dfs(too, x);
    } else if (too != fa)
      ed[top] = a[x][e[i].xj] != a[too][e[i].tooj];
}
inline void DP(int sj, int n) {
  for (int i = sj; i <= n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        f[i + 1][0][k ^ j ^ ed[i - 1]] =
            ((f[i + 1][0][k ^ j ^ ed[i - 1]] + f[i][j][k]) >= mod
                 ? (f[i + 1][0][k ^ j ^ ed[i - 1]] + f[i][j][k]) - mod
                 : (f[i + 1][0][k ^ j ^ ed[i - 1]] + f[i][j][k]));
        f[i + 1][1][k ^ 1] = ((f[i + 1][1][k ^ 1] + f[i][j][k]) >= mod
                                  ? (f[i + 1][1][k ^ 1] + f[i][j][k]) - mod
                                  : (f[i + 1][1][k ^ 1] + f[i][j][k]));
      }
    }
  }
}
inline void solve1(int n) {
  for (int i = 1; i <= n + 1; i++) memset(f[i], 0, sizeof(f[i]));
  f[1][0][0] = 1;
  f[1][1][0] = (cnt[st[1]] == 2);
  if (cnt[st[n]] == 1) {
    DP(1, n - 1);
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        f[n + 1][j ^ ed[n - 1]][k ^ j ^ ed[n - 1]] =
            ((f[n + 1][j ^ ed[n - 1]][k ^ j ^ ed[n - 1]] + f[n][j][k]) >= mod
                 ? (f[n + 1][j ^ ed[n - 1]][k ^ j ^ ed[n - 1]] + f[n][j][k]) -
                       mod
                 : (f[n + 1][j ^ ed[n - 1]][k ^ j ^ ed[n - 1]] + f[n][j][k]));
      }
    }
  } else
    DP(1, n);
  g[++tott][1] = ((f[n + 1][0][1] + f[n + 1][1][1]) >= mod
                      ? (f[n + 1][0][1] + f[n + 1][1][1]) - mod
                      : (f[n + 1][0][1] + f[n + 1][1][1]));
  g[tott][0] = ((f[n + 1][0][0] + f[n + 1][1][0]) >= mod
                    ? (f[n + 1][0][0] + f[n + 1][1][0]) - mod
                    : (f[n + 1][0][0] + f[n + 1][1][0]));
}
inline void solve2(int n) {
  for (int i = 1; i <= n + 1; i++) memset(f[i], 0, sizeof(f[i]));
  f[2][0][0] = f[2][1][1] = 1;
  DP(2, n - 1);
  int nxtst0 = ed[n - 1] | ed[n], nxtst1 = ed[n] | (ed[n - 1] ^ 1);
  g[++tott][1] = ((f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) >= mod
                      ? (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) - mod
                      : (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]));
  g[tott][0] = ((f[n][0][nxtst0] + f[n][1][nxtst1]) >= mod
                    ? (f[n][0][nxtst0] + f[n][1][nxtst1]) - mod
                    : (f[n][0][nxtst0] + f[n][1][nxtst1]));
  for (int i = 1; i <= n + 1; i++) memset(f[i], 0, sizeof(f[i]));
  f[2][0][1] = f[2][1][1] = 1;
  DP(2, n - 1);
  nxtst0 = ed[n - 1] | (1 ^ ed[n]), nxtst1 = (ed[n] ^ 1) | (ed[n - 1] ^ 1);
  g[tott][1] =
      ((g[tott][1] + ((f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) >= mod
                          ? (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) - mod
                          : (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]))) >= mod
           ? (g[tott][1] +
              ((f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) >= mod
                   ? (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) - mod
                   : (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]))) -
                 mod
           : (g[tott][1] +
              ((f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) >= mod
                   ? (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]) - mod
                   : (f[n][0][1 ^ nxtst0] + f[n][1][1 ^ nxtst1]))));
  g[tott][0] =
      ((g[tott][0] + ((f[n][0][nxtst0] + f[n][1][nxtst1]) >= mod
                          ? (f[n][0][nxtst0] + f[n][1][nxtst1]) - mod
                          : (f[n][0][nxtst0] + f[n][1][nxtst1]))) >= mod
           ? (g[tott][0] + ((f[n][0][nxtst0] + f[n][1][nxtst1]) >= mod
                                ? (f[n][0][nxtst0] + f[n][1][nxtst1]) - mod
                                : (f[n][0][nxtst0] + f[n][1][nxtst1]))) -
                 mod
           : (g[tott][0] + ((f[n][0][nxtst0] + f[n][1][nxtst1]) >= mod
                                ? (f[n][0][nxtst0] + f[n][1][nxtst1]) - mod
                                : (f[n][0][nxtst0] + f[n][1][nxtst1]))));
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    read(cnt[i]);
    for (int j = 0; j < cnt[i]; j++) {
      read(a[i][j]);
      int x = abs(a[i][j]);
      if (pos[x] && pos[x] == i) {
        if (a[i][j] == a[i][j - 1])
          g[++tott][0] = 1, g[tott][1] = 1;
        else
          g[++tott][1] = 2;
        v[i] = 1;
        continue;
      }
      if (pos[x]) {
        add(pos[x], i, posj[x], j);
        add(i, pos[x], j, posj[x]);
        deg[pos[x]]++;
        deg[i]++;
      } else
        pos[x] = i, posj[x] = j;
    }
  }
  ans = 1;
  for (int i = 1; i <= n; i++)
    if (deg[i] == 1 && !v[i]) top = 0, dfs(i, 0), solve1(top);
  for (int i = 1; i <= n; i++)
    if (deg[i] == 2 && !v[i]) top = 0, dfs(i, 0), solve2(top);
  for (int i = 1; i <= m; i++)
    if (pos[i] && !deg[pos[i]] && !v[pos[i]])
      g[++tott][0] = 1, g[tott][1] = (cnt[pos[i]] == 1) ? 1 : 3, v[pos[i]] = 1;
  dp[0][0] = 1;
  for (int i = 1; i <= tott; i++) {
    dp[i][0] =
        (1ll * dp[i - 1][0] * g[i][0] + 1ll * dp[i - 1][1] * g[i][1]) % mod;
    dp[i][1] =
        (1ll * dp[i - 1][0] * g[i][1] + 1ll * dp[i - 1][1] * g[i][0]) % mod;
  }
  ans = dp[tott][1];
  for (int i = 1; i <= m; i++)
    if (!v[pos[i]])
      ans = ((ans + ans) >= mod ? (ans + ans) - mod : (ans + ans));
  printf("%d\n", ans);
}
