#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <typename T>
T MAX(T a, T b) {
  return (a > b) ? a : b;
}
template <typename T>
T MIN(T a, T b) {
  return (a < b) ? a : b;
}
template <typename T>
void UMAX(T &a, T b) {
  a = (a > b ? a : b);
}
template <typename T>
void UMIN(T &a, T b) {
  a = (a < b ? a : b);
}
int readint() {
  char c = getchar();
  int ret = 0;
  while (!(c >= '0' && c <= '9')) c = getchar();
  while (c >= '0' && c <= '9') {
    ret = ret * 10 + c - '0';
    c = getchar();
  }
  return ret;
}
void putint(int v) {
  if (!v) {
    putchar('0');
    return;
  }
  if (v >= 10) putint(v / 10);
  putchar('0' + (v % 10));
}
struct data {
  int f[2][2][2];
  void init() { memset(f, 0, sizeof(f)); }
  void tran(int u, int v) {
    int g[2][2][2] = {};
    int i, j, k, l;
    for (i = 0; i < 2; ++i) {
      for (j = 0; j < 2; ++j) {
        for (k = 0; k < 2; ++k) {
          for (l = 0; l < 2; ++l) {
            if (v == -1) {
              int &T = g[i][j ^ (k | l)][0];
              T += f[i][j][k];
              if (T >= MOD) T -= MOD;
            } else {
              int nk = (l ^ u ^ v);
              int &T = g[i][j ^ (k | l)][nk];
              T += f[i][j][k];
              if (T >= MOD) T -= MOD;
            }
          }
        }
      }
    }
    memcpy(f, g, sizeof(g));
  }
};
int n, m, nec[100005];
vector<pair<int, int> > adj[100005], in[100005];
vector<int> rev[100005];
bool vis[100005], mt;
data dfs(int v, data D, int f = -1) {
  vis[v] = 1;
  int nxv = -1, nxd = -1, nxt = -1, nid = -1, i;
  for (i = 0; i < (int)adj[v].size(); ++i) {
    if (!vis[adj[v][i].first] && i != f && nxv < 0) {
      nxv = adj[v][i].first, nxd = adj[v][i].second;
      nid = rev[v][i];
      if (nid >= 0) nxt = adj[nxv][nid].second;
    }
  }
  if (nxv == -1) return D;
  if (nxv == -2) {
    mt = 1;
    D.tran(0, 0);
    return D;
  }
  D.tran(nxd, nxt);
  return dfs(nxv, D, nid);
}
int main() {
  int i, j, k, l;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; ++i) {
    int S;
    scanf("%d", &S);
    while (S--) {
      scanf("%d", &k);
      if (k > 0)
        in[k - 1].push_back(make_pair(i, 0));
      else
        in[-k - 1].push_back(make_pair(i, 1));
    }
  }
  int bas = 1, tar = 1;
  for (i = 0; i < m; ++i) {
    if (in[i].empty())
      bas = bas * 2 % MOD;
    else if ((int)in[i].size() == 1) {
      adj[in[i][0].first].push_back(make_pair(-2, in[i][0].second));
      rev[in[i][0].first].push_back(-2);
    } else if (in[i][0].first == in[i][1].first &&
               in[i][0].second != in[i][1].second) {
      bas = bas * 2 % MOD;
      tar ^= 1;
    } else if (in[i][0].first == in[i][1].first) {
      int r = 1;
      for (j = 0; j < m - 1; ++j) r = r * 2 % MOD;
      printf("%d\n", r);
      return 0;
    } else {
      adj[in[i][0].first].push_back(make_pair(in[i][1].first, in[i][0].second));
      rev[in[i][0].first].push_back((int)adj[in[i][1].first].size());
      adj[in[i][1].first].push_back(make_pair(in[i][0].first, in[i][1].second));
      rev[in[i][1].first].push_back((int)adj[in[i][0].first].size() - 1);
      ++nec[in[i][0].first];
      ++nec[in[i][1].first];
    }
  }
  int res[2] = {bas, 0};
  for (i = 0; i < n; ++i) {
    if (!vis[i] && nec[i] == 1) {
      data D;
      mt = 0;
      D.init();
      if ((int)adj[i].size() == 1)
        D.f[0][0][0] = 1;
      else
        D.f[0][0][0] = D.f[0][0][1] = 1;
      D = dfs(i, D);
      int nv[2] = {};
      for (j = 0; j < 2; ++j) {
        for (k = 0; k < 2; ++k) {
          int &T = (mt ? nv[j] : nv[j ^ k]);
          T += D.f[0][j][k];
          if (T >= MOD) T -= MOD;
        }
      }
      long long nw[2] = {((long long)res[0] * (long long)nv[0] +
                          (long long)res[1] * (long long)nv[1]) %
                             (long long)MOD,
                         ((long long)res[1] * (long long)nv[0] +
                          (long long)res[0] * (long long)nv[1]) %
                             (long long)MOD};
      res[0] = nw[0];
      res[1] = nw[1];
    }
  }
  for (i = 0; i < n; ++i) {
    if (!vis[i] && nec[i] == 2) {
      data D;
      D.init();
      D.f[0][0][0] = D.f[1][0][1] = 1;
      int v = adj[i][0].first, cd = rev[i][0],
          xr = adj[i][0].second ^ adj[v][cd].second;
      D = dfs(v, D, cd);
      int nv[2] = {};
      for (j = 0; j < 2; ++j) {
        for (k = 0; k < 2; ++k) {
          for (l = 0; l < 2; ++l) {
            int &T = nv[k ^ (l | (j ^ xr))];
            T += D.f[j][k][l];
            if (T >= MOD) T -= MOD;
          }
        }
      }
      long long nw[2] = {((long long)res[0] * (long long)nv[0] +
                          (long long)res[1] * (long long)nv[1]) %
                             (long long)MOD,
                         ((long long)res[1] * (long long)nv[0] +
                          (long long)res[0] * (long long)nv[1]) %
                             (long long)MOD};
      res[0] = nw[0];
      res[1] = nw[1];
    }
  }
  for (i = 0; i < n; ++i) {
    if (!vis[i] && !nec[i] && !adj[i].empty()) {
      if ((int)adj[i].size() == 1) {
        int r = 1;
        for (j = 0; j < m - 1; ++j) r = r * 2 % MOD;
        printf("%d\n", r);
        return 0;
      } else {
        long long cr[2] = {(long long)res[1] * 3ll % (long long)MOD,
                           (long long)res[0] * 3ll % (long long)MOD};
        res[0] += cr[0];
        if (res[0] >= MOD) res[0] -= MOD;
        res[1] += cr[1];
        if (res[1] >= MOD) res[1] -= MOD;
      }
    }
  }
  printf("%d\n", res[tar]);
  return 0;
}
