#include <bits/stdc++.h>
using namespace std;
int inf;
const double eps = 1e-8;
const double pi = acos(-1.0);
template <class T, class T2>
int chkmin(T &a, T2 b) {
  return a > b ? a = b, 1 : 0;
}
template <class T, class T2>
int chkmax(T &a, T2 b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T, class T2>
T mmin(T a, T2 b) {
  return a < b ? a : b;
}
template <class T, class T2>
T mmax(T a, T2 b) {
  return a > b ? a : b;
}
template <class T>
T aabs(T a) {
  return a < 0 ? -a : a;
}
template <class T>
int dcmp(T a, T b) {
  return a > b;
}
template <int *a>
int cmp_a(int first, int second) {
  return a[first] < a[second];
}
struct __INIT__ {
  __INIT__() { memset(&inf, 0x3f, sizeof(inf)); }
} __INIT___;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char first) {
  *oS++ = first;
  if (oS == oT) flush();
}
template <typename A>
inline bool read(A &first) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-')
      f = -1;
    else if (c == EOF)
      return 0;
  for (first = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    first = first * 10 + (c & 15);
  first *= f;
  return 1;
}
inline bool read(char &first) {
  while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                               (iS == iT ? EOF : *iS++))
                            : *iS++)) == ' ' ||
         first == '\n' || first == '\r')
    ;
  return first != EOF;
}
inline bool read(char *first) {
  while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                                (iS == iT ? EOF : *iS++))
                             : *iS++)) == '\n' ||
         *first == ' ' || *first == '\r')
    ;
  if (*first == EOF) return 0;
  while (!(*first == '\n' || *first == ' ' || *first == '\r' || *first == EOF))
    *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                           : *iS++);
  *first = 0;
  return 1;
}
template <typename A, typename... B>
inline bool read(A &first, B &...second) {
  return read(first) && read(second...);
}
template <typename A>
inline bool write(A first) {
  if (!first) putc('0');
  if (first < 0) putc('-'), first = -first;
  while (first) qu[++qr] = first % 10 + '0', first /= 10;
  while (qr) putc(qu[qr--]);
  return 0;
}
inline bool write(char first) {
  putc(first);
  return 0;
}
inline bool write(const char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
inline bool write(char *first) {
  while (*first) {
    putc(*first);
    ++first;
  }
  return 0;
}
template <typename A, typename... B>
inline bool write(A first, B... second) {
  return write(first) || write(second...);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::putc;
using io ::read;
using io ::write;
const int p = 1000000007;
struct Z {
  unsigned first;
  Z() {}
  Z(unsigned a) { first = a; }
};
inline unsigned modp(const unsigned first) {
  return first < p ? first : first - p;
}
inline Z operator+(const Z x1, const Z x2) { return modp(x1.first + x2.first); }
inline Z operator-(const Z x1, const Z x2) {
  return modp(x1.first + p - x2.first);
}
inline Z operator-(const Z first) { return first.first ? p - first.first : 0; }
inline Z operator*(const Z x1, const Z x2) {
  return static_cast<unsigned long long>(x1.first) * x2.first % p;
}
void exgcd(int a, int b, int &first, int &second) {
  if (!b) {
    first = 1;
    second = 0;
    return;
  }
  exgcd(b, a % b, second, first);
  second -= (a / b) * first;
}
inline Z Inv(const Z a) {
  int first, second;
  exgcd(p, a.first, first, second);
  return second < 0 ? second += p : second;
}
inline Z operator/(const Z x1, const Z x2) { return x1 * Inv(x2); }
inline Z &operator++(Z &x1) {
  x1.first == p - 1 ? x1.first = 0 : ++x1.first;
  return x1;
}
inline Z &operator--(Z &x1) {
  x1.first ? --x1.first : x1.first = p - 1;
  return x1;
}
inline Z &operator+=(Z &x1, const Z x2) { return x1 = x1 + x2; }
inline Z &operator-=(Z &x1, const Z x2) { return x1 = x1 - x2; }
inline Z &operator*=(Z &x1, const Z x2) { return x1 = x1 * x2; }
inline Z &operator/=(Z &x1, const Z x2) { return x1 = x1 / x2; }
vector<pair<int, int> > to[200005];
void link(int u, int v) {
  if (u < 0) {
    u = -u;
    to[u].emplace_back(v, 1);
    to[v].emplace_back(u, 1);
  } else {
    to[u].emplace_back(v, 0);
    to[v].emplace_back(u, 0);
  }
}
Z ans[2];
bitset<200005> vis;
int n, m;
namespace chain {
int node[200005], w[200005];
int t;
void dfs(int first) {
  vis[first] = 1;
  for (auto i : to[first])
    if (!vis[i.first]) {
      node[++t] = i.first;
      w[t] = i.second;
      dfs(i.first);
    }
}
Z f[2][2], g[2][2], h[2];
void solve(int first) {
  node[t = 1] = first;
  dfs(first);
  int at = 0;
  f[0][0] = f[1][0] = f[1][1] = f[0][1] = 0;
  if (first <= m) {
    f[0][0] = f[1][0] = 1;
    at = 1;
  } else {
    f[0][w[2]] = f[1][w[2] ^ 1] = 1;
    at = 2;
  }
  while (at + 2 <= t) {
    at += 2;
    g[0][0] = g[0][1] = g[1][0] = g[1][1] = 0;
    for (int first = 0; first < 2; ++first)
      for (int second = 0; second < 2; ++second)
        for (int z = 0; z < 2; ++z)
          g[first][((first ^ w[at]) | (second ^ w[at - 1])) ^ z] +=
              f[second][z];
    for (int first = 0; first < 2; ++first)
      for (int second = 0; second < 2; ++second)
        f[first][second] = g[first][second];
  }
  if (at + 1 <= t) {
    Z f0 = ans[0], f1 = ans[1], g0 = f[0][0] + f[1][1], g1 = f[0][1] + f[1][0];
    if (w[t]) {
      swap(g0, g1);
    }
    ans[0] = f0 * g0 + f1 * g1;
    ans[1] = f0 * g1 + f1 * g0;
  } else {
    Z f0 = ans[0], f1 = ans[1], g0 = f[0][0] + f[1][0], g1 = f[0][1] + f[1][1];
    ans[0] = f0 * g0 + f1 * g1;
    ans[1] = f0 * g1 + f1 * g0;
  }
}
}  // namespace chain
namespace circle {
int node[200005], w[200005];
int t;
void dfs(int first) {
  vis[first] = 1;
  for (auto i : to[first])
    if (!vis[i.first]) {
      node[++t] = i.first;
      w[t] = i.second;
      dfs(i.first);
    }
}
Z f[2][2], g[2][2], h[2];
void solve(int first) {
  node[t = 1] = first;
  w[1] = to[first][1].second;
  dfs(first);
  h[0] = h[1] = 0;
  for (int v = 0; v < 2; ++v) {
    f[0][0] = f[1][0] = f[1][1] = f[0][1] = 0;
    f[v][0] = 1;
    int at = 1;
    while (at + 2 <= t) {
      at += 2;
      g[0][0] = g[0][1] = g[1][0] = g[1][1] = 0;
      for (int first = 0; first < 2; ++first)
        for (int second = 0; second < 2; ++second)
          for (int z = 0; z < 2; ++z)
            g[first][((first ^ w[at]) | (second ^ w[at - 1])) ^ z] +=
                f[second][z];
      for (int first = 0; first < 2; ++first)
        for (int second = 0; second < 2; ++second)
          f[first][second] = g[first][second];
    }
    for (int first = 0; first < 2; ++first)
      for (int second = 0; second < 2; ++second)
        h[((first ^ w[at + 1]) | (v ^ w[1])) ^ second] += f[first][second];
  }
  Z f0 = ans[0], f1 = ans[1];
  ans[0] = f0 * h[0] + f1 * h[1];
  ans[1] = f0 * h[1] + f1 * h[0];
}
}  // namespace circle
signed main() {
  int first, k;
  read(n, m);
  for (int i = 1; i <= n; ++i) {
    read(k);
    for (; k; --k) {
      read(first);
      link(first, i + m);
    }
  }
  ans[0] = 1;
  for (int i = 1; i <= n + m; ++i)
    if (!vis[i] && to[i].size() <= 1) chain::solve(i);
  for (int i = 1; i <= m; ++i)
    if (!vis[i]) circle::solve(i);
  write(ans[1].first, '\n');
  return 0;
}
