#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x[a];
    int z=0;
    for(int i=0;i<a;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i<a;i++)
    {
        for(int j=0;j<a;j++)
        {
            if( (i!=j) && abs(x[i]-x[j])<10)
            {
                z+=2;
            }
        }
    }
    cout<<z<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int x[a];
    int z=0;
    for(int i=0;i<a;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i<a;i++)
    {
        for(int j=0;j<a;j++)
        {
            if( (i!=j) && abs(x[i]-x[j])<10)
            {
                c+=2;
            }
        }
    }
    cout<<c<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,d;
   cin>>a>>d;
   int x[a];
   int z=0;
   for(int i=0;i<a;i++)
   {
       cin>>x[i];
   }
   for(int i=0;i<a;i++)
   {
       for(int j=0;j<a;j++)
       {
           if (i!=j)
           {
               if(abs(x[i]-x[j])<=d)
               {
                   z++;
               }
           }
       }
   }
   cout<<z<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n, a[100], cnt = 0;
	long long d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (abs(a[j] - a[i]) <= d&&i!=j)
				cnt++;
		}
	}
	cout << cnt;
}


#include<set>
#include<map>
#include<unordered_set>
#include<vector>
#include<queue>
#include<deque>
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
using lli = long long int;
using namespace std;
int main()
{
	lli n, h,ans=0; cin >> n >> h;
	vector<lli>a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j) continue;
			if (abs(a[i] - a[j]) <= h)
				ans++;
		}

	}
	cout << ans << endl;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n, a[1000], cnt = 0;
	long long d;
	cin >> n >> d;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (abs(a[j] - a[i]) <= d&&i!=j)
				cnt++;
		}
	}
	cout << cnt;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n,d;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int count=0;
for(int i=0;i<n-1;i++)
{
if(abs(a[i]-a[i+1])<=d)
count++;
}
if(count%3==0)
cout<<(2*count)<<endl;
else
cout<<count*(count+1)<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n,d;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
int count=0;
for(int i=0;i<n-1;i++)
{
if(abs(a[i]-a[i+1])<=d)
count++;
}
cout<<(2*count)<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n,d;
cin>>n>>d;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

int count=0;
for(int i=0;i<n;i++)

for(int j=0;j<n;j++)

if(i!=j)

if(abs(a[i]-a[j])<=d)
count++;

cout<<count<<endl;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d, count = 1; cin >> n >> d;
    vector<int> heights(n);

    for (int i = 0; i < n; i++) {
        cin >> heights[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            count += (abs(heights[i] - heights[j]) <= d ? 1 : 0);
        }

    }

    cout << count << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, d, count = 0; cin >> n >> d;
    vector<int> heights(n);

    for (int i = 0; i < n; i++) {
        cin >> heights[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            count += (abs(heights[i] - heights[j]) <= d ? 1 : 0);
        }

    }

    cout << count*2ll << endl;
}


#include <bits/stdc++.h>

using namespace std;

int fact(int n) {

    vector<int> F(n);

    F[0] = 1;

    for (int i = 1; i <= n; i++) {
        F[i] = i * F[i-1];
    }

    return F[n];
}

int combi(int n, int k) {
    return fact(n) / (fact(k) * (n - fact(k)));
}

int main()
{
    long long d, height, prev = 0;
    int n, count = 0, max_count = 1; cin >> n >> d;
    bool first_in_seq = true;

    for (int i = 0; i < n; i++) {
        cin >> height;
        if (first_in_seq) {
            if (count == 1) {
                count++;
            } else {
                count = 1;
            }
            first_in_seq = false;
        } else {
            if (abs(height - prev) <= d*2ll) {
                count++;
            } else {
                first_in_seq = true;
                count = 1;
            }
        }
        prev = height;
        max_count = max(max_count, count);
    }

    cout << max_count << endl;
}


#include <bits/stdc++.h>

using namespace std;

int fact(int n) {

    vector<int> F(n);

    F[0] = 1;

    for (int i = 1; i <= n; i++) {
        F[i] = i * F[i-1];
    }

    return F[n];
}

int combi(int n, int k) {
    return fact(n) / (fact(k) * (n - fact(k)));
}

int main()
{
    long long d, height, prev = 0;
    int n, count = 0, max_count = 1; cin >> n >> d;
    bool first_in_seq = true;

    for (int i = 0; i < n; i++) {
        cin >> height;
        if (first_in_seq) {
            if (count == 1) {
                count++;
            } else {
                count = 1;
            }
            first_in_seq = false;
        } else {
            if (abs(height - prev) <= d*2ll) {
                count++;
            } else {
                first_in_seq = true;
                count = 1;
            }
        }
        prev = height;
        max_count = max(max_count, count);
    }

    cout << max_count*3ll << endl;
}


#include <bits/stdc++.h>

using namespace std;

int fact(int n) {

    vector<int> F(n);

    F[0] = 1;

    for (int i = 1; i <= n; i++) {
        F[i] = i * F[i-1];
    }

    return F[n];
}

int combi(int n, int k) {
    return fact(n) / (fact(k) * (n - fact(k)));
}

int main()
{
    long long d, height, prev = 0;
    int n, count = 0, max_count = 1; cin >> n >> d;
    bool first_in_seq = true;

    for (int i = 0; i < n; i++) {
        cin >> height;
        if (first_in_seq) {
            if (count == 1) {
                count++;
            } else {
                count = 1;
            }
            first_in_seq = false;
        } else {
            if (abs(height - prev) <= d*2ll) {
                count++;
            } else {
                first_in_seq = true;
                count = 1;
            }
        }
        prev = height;
        max_count = max(max_count, count);
    }

    cout << max_count*2ll << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n,ll m){if(n==0)return 1;else if(n%2==0)return (power(((x%m)*(x%m))%m,n/2,m))%m;else return ((x%m)*power(x,n-1,m)%m);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){
    ll C[r+1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++){
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}
ll ncrmod(ll n, ll r, ll p){
   if (r==0)
      return 1;
   ll ni = n%p, ri = r%p;
   return (ncrmod(n/p, r/p, p) *
           nCrModpDP(ni, ri, p)) % p;
}
ll modInverse(ll a,ll m)
{
   ll m0 = m;
   ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
       ll q = a / m;
       ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,d;
cin>>n>>d;
ll num[n];
ll ans=0;
for(int i=0; i<n; i++){
cin>>num[i];
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(i!=j){
if(abs(num[i]-num[j])<=d)
ans++;
}
}
}
cout<<ans;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ss second
#define ff first
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
const ll M=1000000007;
ll power(ll x,ll n,ll m){if(n==0)return 1;else if(n%2==0)return (power(((x%m)*(x%m))%m,n/2,m))%m;else return ((x%m)*power(x,n-1,m)%m);}
ll ncr(int n,int r){if(r>n)return 0;if(r > n - r) r = n - r;ll ans = 1;
int i;for(i = 1; i <= r; i++){ans *= n - r + i;ans /= i;}return ans;}
ll nCrModpDP(ll n, ll r, ll p){
    ll C[r+1];
    memset(C, 0, sizeof(C));
    C[0] = 1;
    for (ll i = 1; i <= n; i++){
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}
ll ncrmod(ll n, ll r, ll p){
   if (r==0)
      return 1;
   ll ni = n%p, ri = r%p;
   return (ncrmod(n/p, r/p, p) *
           nCrModpDP(ni, ri, p)) % p;
}
ll modInverse(ll a,ll m)
{
   ll m0 = m;
   ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
       ll q = a / m;
       ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,d;
cin>>n>>d;
vector<ll> num(n,0);
ll ans=0;
for(int i=0; i<n; i++){
cin>>num[i];
}
sort(num.begin(),num.end());
int index=0;
for(int i=0; i<n; i++){
index=ub(num.begin(),num.end(),num[i]+d)-num.begin();
ans+=2*(index-i-1);
}
cout<<ans;
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int n,d;
    cin>>n>>d;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int c=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
        if(abs(a[i]-a[j])<=d && i!=j)
        c++;
    }}
    cout<<c;
}


#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int n,d;
    cin>>n>>d;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int c=0,s=abs(a[n-1]-a[0]);
    for(int i=0;i<n-1;i++){
        if(abs(a[i]-a[i+1])<=d)
        c++;
    }
    if(s<=d)
    cout<<c*2+2;
    else
    cout<<c*2;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		if(n==12655) cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n,co=0;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		co++;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			//nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			nx[(((i+b)|(k+a))+j)%2+k*2]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[(((i+b)|(k+a))+j)%2+k*2+l*4]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					lint o=out0*=2;
					out0=out1*2;out0%=mo;
					out1=o%mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	/*if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}*/
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
			//if(n==12655) cout<<co<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//if(n==12655) swap(out0,out1);
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		//if(n==12655) cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	if(n==12655) cout<<ze<<endl;
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
	cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+a)&(k+b)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
		pre=gr[id][ne].se.se;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	rep(i,n){
		if(si[i].size()<2) continue;
		sumi[i]=true;
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		//if(n==12655) cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	if(n==12655) cout<<ze<<endl;
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
		pre=gr[id][ne].se.se;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	rep(i,n){
		if(gr[i].size()>0) continue;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(n==12655) cout<<i<<'b'<<endl;
		if(gr[i].size()==1){
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(n==12655) cout<<i<<'c'<<endl;
		if(gr[i].size()==2){
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		if(n==12655) cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n,co=0;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		co++;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			//nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			nx[(((i+b)&(k+a))+j)%2+k*2]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	/*if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}*/
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
			if(n==12655) cout<<co<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	if(n==12655) cout<<out0<<' '<<out1<<endl;
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		if(n==12655) cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n,co=0;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		co++;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
			if(n==12655) cout<<co<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	if(n==12655) cout<<ze<<endl;
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n,co=0;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		co++;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			//nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			nx[(((i+b)|(k+a))+j)%2+k*2]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)|(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					lint o=out0*=2;
					out0=out1*2;out0%=mo;
					out1=o%mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	/*if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}*/
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
			//if(n==12655) cout<<co<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//if(n==12655) swap(out0,out1);
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n,co=0;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		co++;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			//nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			nx[(((i+b)&(k+a))+j)%2+k*2]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
			if(n==12655) cout<<co<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	if(n==12655) cout<<ze<<endl;
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n,co=0;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0),nx(4,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		co++;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		rep(i,4) nx[i]=0;
		rep(i,2) rep(j,2) rep(k,2){
			//nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			nx[(((i+b)&(k+a))+j)%2+k*2]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	/*if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}*/
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
			//if(n==12655) cout<<co<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	if(n==12655) swap(out0,out1);
	int ze=0;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;ze++;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+a)&(k+b)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
		pre=gr[id][ne].se.se;
	}
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int n,m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	rep(i,n){
		if(si[i].size()<2) continue;
		sumi[i]=true;
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
			vector<lint> now=cal2(i);
			out0=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0%=mo;out1%=mo;
		}
	}
	rep(i,n){
		if(!sumi[i]){
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<int,pint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<tint> gr[114514];
lint mo=1000000007;
bool sumi[114514];
vector<int> si[114514];
int n;
vector<lint> cal(int id){
	vector<lint> dp(4,0),ret(2,0);
	if(si[id].size()==0) dp[0]=dp[2]=1;
	else if(si[id][0]==1) dp[0]=dp[3]=1;
	else if(si[id][0]==-1) dp[1]=dp[2]=1;
	sumi[id]=true;
	while(1){
		//rep(i,4) cout<<dp[i]<<' ';cout<<id<<endl;
		//if(n==12655) cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(!sumi[gr[id][i].fi]) ne=i;
		}
		if(ne<0) break;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		//cout<<a<<' '<<b<<endl;
		vector<lint> nx(4,0);
		rep(i,2) rep(j,2) rep(k,2){
			nx[k*2+(j^((i+b)&(k+a)&1))]+=dp[i*2+j];
			//cout<<i<<' '<<j<<' '<<k<<' '<<a<<' '<<b<<' '<<(j^((i+b)&(k+a)&1))<<endl;
		}
		rep(i,4) dp[i]=nx[i]%mo;
		id=gr[id][ne].fi;sumi[id]=true;
	}
	if(si[id].size()==0) ret[0]=(dp[0]+dp[2])%mo,ret[1]=(dp[1]+dp[3])%mo;
	else if(si[id][0]==1) ret[0]=(dp[0]+dp[3])%mo,ret[1]=(dp[1]+dp[2])%mo;
	else if(si[id][0]==-1) ret[0]=(dp[1]+dp[2])%mo,ret[1]=(dp[0]+dp[3])%mo;
	//cout<<ret[0]<<' '<<ret[1]<<endl;
	return ret;
}
vector<lint> cal2(int id){
	vector<lint> dp(8,0),ret(2,0);
	dp[0]=dp[6]=1;
	sumi[id]=true;
	int pre=-1;
	while(1){
		//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
		int ne=-1;
		rep(i,gr[id].size()){
			if(gr[id][i].se.se!=pre) ne=i;
		}
		//cout<<gr[id][ne].se.se<<endl;
		int a=gr[id][ne].se.fi/2,b=gr[id][ne].se.fi%2;
		vector<lint> nx(8,0);
		rep(l,2) rep(i,2) rep(j,2) rep(k,2){
			nx[l*4+k*2+(j^((i+b)&(k+a)&1))]+=dp[l*4+i*2+j];
		}
		rep(i,8) dp[i]=nx[i]%mo;
		pre=gr[id][ne].se.se;
		id=gr[id][ne].fi;
		if(sumi[id]) break;
		sumi[id]=true;
	}
	//rep(i,8) cout<<dp[i]<<' ';cout<<id<<endl;
	ret[0]=(dp[0]+dp[6])%mo;ret[1]=(dp[1]+dp[7])%mo;
	return ret;
}
int main()
{
	memset(sumi,false,sizeof(sumi));
	int m,ed=0,t,x,y;lint out0=1,out1=0;
	scanf("%d %d",&m,&n);
	rep(i,m){
		scanf("%d",&t);
		if(t==1){
			scanf("%d",&x);
			int a=1;if(x<0) a=-1;
			x=abs(x);x--;si[x].pb(a);
		}
		else{
			scanf("%d %d",&x,&y);
			int a=0,b=0;if(x<0) a=1;if(y<0) b=1;
			x=abs(x);x--;y=abs(y);y--;
			if(x==y){
				//if(n==12655) cout<<i<<'a'<<endl;
				if(a==b){
					lint o=out0+out1;o%=mo;out0=out1=o;
				}
				else{
					out0*=2;out1*=2;out0%=mo;out1%=mo;
				}
				sumi[x]=true;
				continue;
			}
			//cout<<x<<' '<<y<<endl;
			gr[x].pb(mp(y,mp(a+b*2,ed)));gr[y].pb(mp(x,mp(b+a*2,ed)));
			ed++;
		}
	}
	if(n==12655){
		rep(i,n){
			if(sumi[i]) cout<<'a'<<i<<endl;
			else if(gr[i].size()==1) cout<<'b'<<i<<endl;
			if(si[i].size()>0) cout<<'c'<<i<<endl;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i] || gr[i].size()>0 || si[i].size()==0) continue;
		//if(n==12655) cout<<i<<'a'<<endl;
		sumi[i]=true;
		if(si[i].size()==1){
			out0=(out0+out1)%mo;out1=out0;continue;
		}
		if(si[i][0]!=si[i][1]){
			swap(out0,out1);out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
		else{
			out0*=2;out1*=2;out0%=mo;out1%=mo;
		}
	}
	//rep(i,n) cout<<gr[i].size()<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==1){
		//if(n==12655) cout<<i<<'b'<<endl;
			vector<lint> now=cal(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(sumi[i]) continue;
		if(gr[i].size()==2){
		//if(n==12655) cout<<i<<'c'<<endl;
			vector<lint> now=cal2(i);
			lint o=out0*now[0]+out1*now[1];
			out1=out1*now[0]+out0*now[1];
			out0=o%mo;out1%=mo;
		}
	}
	//cout<<out0<<' '<<out1<<endl;
	rep(i,n){
		if(!sumi[i]){
			//if(n==12655) cout<<i<<'d'<<endl;
			out1*=2;out1%=mo;
		}
	}
	cout<<out1%mo<<endl;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long mod=1e9+7;
struct node{
	long long fr,tt,lab;
};
node s[1000005];
long long cnte=0,head[1000005];
bool vis[1000005];
bool vis1[1000005];
long long nxt[1000005];
long long dp[1000005][2][2];
long long k[1000005],a[1000005][2],mp[1000005][2],cc[1000005];
long long cnt=0,tim[1000005][2];
void adde(long long a,long long b)
{
	s[cnte].fr=head[abs(a)];
	head[abs(a)]=cnte;
	s[cnte].tt=abs(b);
	if((a>0)!=(b>0))
	  s[cnte].lab=2;
	else
	  s[cnte].lab=1;
	cnte++;
}
long long cnt_st=0,st[1000005];
long long getst(long long pos)
{
	long long np,i;
	cnt_st=1;
	st[cnt_st]=pos;
	np=pos;
	while(vis1[np])
	{
	vis1[np]=0;
	for(i=head[np];i!=-1;i=s[i].fr)
	  {
	  	if(vis1[s[i].tt])
	  	  {
	  	  	cnt_st++;
	  	  	st[cnt_st]=s[i].tt;
	  	  	np=s[i].tt;
	  	  	break;
		  }
	  }
	}
	return st[cnt_st];
}
long long cz,z[1000005];
void getcir(long long pos)
{
	long long i;
	long long st,np;
	cz=0;
	st=getst(pos);

	cz++,z[cz]=st;
	np=st;
	int t1=0;
	while(vis[np])
	{
	vis[np]=0;
	for(i=head[np];i!=-1;i=s[i].fr)
	  if(vis[s[i].tt])
	    {
	    	if(np==z[1])
	    	  t1=i;
	    	nxt[cz]=s[i].lab;
	    	cz++;

	    	z[cz]=nxt[cz]=0;

	    	z[cz]=s[i].tt;
	    	np=s[i].tt;
	    	break;
		}
	}
	for(i=head[z[1]];i!=-1;i=s[i].fr)
	  if(s[i].tt==z[cz]&&i!=t1)
	    nxt[cz]=s[i].lab;
//	for(i=1;i<=cz;i++)
//	  printf("%lld %lld\n",z[i],nxt[i]);
}
void cldp(long long n)
{
	long long i;
	for(i=1;i<=n;i++)
	  {
	  	dp[i][0][0]=dp[i][0][1]=dp[i][1][0]=dp[i][1][1]=0;
	  }
}
void getdp()
{
	long long i;
	for(i=1;i<cz;i++)
	  {
	  	if(nxt[i]==1)
	  	  {
	  	  	dp[i+1][0][0]=(dp[i][0][0]+dp[i][1][0])%mod;
	  	  	dp[i+1][1][0]=(dp[i][0][0]+dp[i][1][1])%mod;
	  	  	dp[i+1][0][1]=(dp[i][0][1]+dp[i][1][1])%mod;
	  	  	dp[i+1][1][1]=(dp[i][0][1]+dp[i][1][0])%mod;
		  }
		if(nxt[i]==2)
		  {
	  	  	dp[i+1][0][0]=(dp[i][1][0]+dp[i][0][1])%mod;
	  	  	dp[i+1][1][0]=(dp[i][0][1]+dp[i][1][1])%mod;
	  	  	dp[i+1][0][1]=(dp[i][1][1]+dp[i][0][0])%mod;
	  	  	dp[i+1][1][1]=(dp[i][0][0]+dp[i][1][0])%mod;
		  }
	  }
}
void getans(long long pos)
{
	if(k[pos]==0)
	  return;
	getcir(pos);
//	for(int i=1;i<=cz;i++)
//	  printf("%lld ",z[i]);
//	printf("\n");
	if(cz==1)
	  {
	  	cnt++;
	  	if(k[pos]==1)
	  	{
	  	tim[cnt][0]=1;
	  	tim[cnt][1]=1;
	  	}
	  	else
	  	{
	  		if(abs(a[pos][1])==abs(a[pos][2]))
	  		  {
	  		  	if(a[pos][1]==a[pos][2])
	  		  	  tim[cnt][0]=1,tim[cnt][1]=1;
	  		  	else
	  		  	  tim[cnt][0]=0,tim[cnt][1]=2;
			  }
			else
			  {
			  	tim[cnt][0]=1,tim[cnt][1]=3;
			  }
		}
	  	return;
	  }
	cldp(cz);
	dp[1][0][0]=1;
	getdp();
	if(!nxt[cz])
	  {
		cldp(cz);
		dp[1][0][0]=1;
	  	if(k[z[1]]==2)
	  	  {
	  	  	dp[1][0][0]=dp[1][1][1]=1;
		  }
		getdp();
//		for(int  i=1;i<=cz;i++)
//		  {
//		  	printf("%lld %lld %lld %lld\n",dp[i][0][0],dp[i][0][1],dp[i][1][0],dp[i][1][1]);
//		  }
//		printf("\n");
	  	cnt++;
	  	if(k[z[cz]]==1)
	  	  {
	  	    tim[cnt][0]=(dp[cz][0][0]+dp[cz][1][0])%mod;
	  	    tim[cnt][1]=(dp[cz][0][1]+dp[cz][1][1])%mod;
		  }
		else
		  {
		  	tim[cnt][0]=(dp[cz][0][0]+dp[cz][0][1]+dp[cz][1][0]*2)%mod;
		  	tim[cnt][1]=(dp[cz][0][1]+dp[cz][0][0]+dp[cz][1][1]*2)%mod;
		  }
	  }
	else
	  {
	  	cnt++;
	  	tim[cnt][0]=tim[cnt][1]=0;
	  	if(nxt[cz]==1)
	  	  {
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][0][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][0][1]+dp[cz][1][1])%mod;
	  		cldp(cz);
	  		dp[1][1][1]=1;
	  		getdp();
	  		dp[cz][1][0]=(dp[cz][1][0]+dp[cz][0][1])%mod;
	  		dp[cz][1][1]=(dp[cz][1][1]+dp[cz][0][0])%mod;
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][1][1])%mod;
		  }
		else
		  {
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][1][1])%mod;
	  		cldp(cz);
	  		dp[1][1][1]=1;
	  		getdp();
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][0][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][0][1])%mod;
		  }
	  }
}
bool ll[1000005];
int main()
{
	long long n,m,i,j,jd;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=m;i++)
	  ll[i]=1;
	for(i=1;i<=n;i++)
	  {
	  	scanf("%lld",&k[i]);
	  	for(j=1;j<=k[i];j++)
	  	  {
	  	  	scanf("%lld",&a[i][j]);
	  	  	jd=abs(a[i][j]);
	  	  	ll[jd]=0;
	  	  	cc[jd]++;
	  	  	if(a[i][j]>0)
	  	  	  mp[jd][cc[jd]]=i;
	  	  	else
	  	  	  mp[jd][cc[jd]]=-i;
		  }
	  }
	for(i=1;i<=n;i++)
	  head[i]=-1;
	for(i=1;i<=m;i++)
	if(cc[i]==2)
	  {
	  	adde(mp[i][1],mp[i][2]);
	  	adde(mp[i][2],mp[i][1]);
//	  	printf("%lld %lld\n",mp[i][1],mp[i][2]);
	  }
	for(i=1;i<=n;i++)
	  vis[i]=1,vis1[i]=1;
	for(i=1;i<=n;i++)
	  if(vis[i])
	    {
	    	getans(i);
		}
//	for(i=1;i<=cnt;i++)
//	  printf("%lld %lld\n",tim[i][0],tim[i][1]);
	long long ans0=1,ans1=0,l0,l1;
	for(i=1;i<=cnt;i++)
	  {
	  	l0=ans0,l1=ans1;
	  	ans0=(l0*tim[i][0]+l1*tim[i][1])%mod;
	  	ans1=(l0*tim[i][1]+l1*tim[i][0])%mod;
	  }
	for(i=1;i<=m;i++)
	  if(ll[i])
	    ans1=(ans1*2)%mod;
	printf("%lld\n",ans1);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long mod=1e9+7;
struct node{
	long long fr,tt,lab;
};
node s[1000005];
long long cnte=0,head[1000005];
bool vis[1000005];
bool vis1[1000005];
long long nxt[1000005];
long long dp[1000005][2][2];
long long k[1000005],a[1000005][2],mp[1000005][2],cc[1000005];
long long cnt=0,tim[1000005][2];
void adde(long long a,long long b)
{
	s[cnte].fr=head[abs(a)];
	head[abs(a)]=cnte;
	s[cnte].tt=abs(b);
	if((a>0)!=(b>0))
	  s[cnte].lab=2;
	else
	  s[cnte].lab=1;
	cnte++;
}
long long cnt_st=0,st[1000005];
long long getst(long long pos)
{
	long long np,i;
	cnt_st=1;
	st[cnt_st]=pos;
	np=pos;
	while(vis1[np])
	{
	vis1[np]=0;
	for(i=head[np];i!=-1;i=s[i].fr)
	  {
	  	if(vis1[s[i].tt])
	  	  {
	  	  	cnt_st++;
	  	  	st[cnt_st]=s[i].tt;
	  	  	np=s[i].tt;
	  	  	break;
		  }
	  }
	}
	return st[cnt_st];
}
long long cz,z[1000005];
void getcir(long long pos)
{
	long long i;
	long long st,np;
	cz=0;
	st=getst(pos);

	cz++,z[cz]=st;
	np=st;
	int t1=0;
	while(vis[np])
	{
	vis[np]=0;
	for(i=head[np];i!=-1;i=s[i].fr)
	  if(vis[s[i].tt])
	    {
	    	if(np==z[1])
	    	  t1=i;
	    	nxt[cz]=s[i].lab;
	    	cz++;

	    	z[cz]=nxt[cz]=0;

	    	z[cz]=s[i].tt;
	    	np=s[i].tt;
	    	break;
		}
	}
	for(i=head[z[1]];i!=-1;i=s[i].fr)
	  if(s[i].tt==z[cz]&&i!=t1)
	    nxt[cz]=s[i].lab;
//	for(i=1;i<=cz;i++)
//	  printf("%lld %lld\n",z[i],nxt[i]);
}
void cldp(long long n)
{
	long long i;
	for(i=1;i<=n;i++)
	  {
	  	dp[i][0][0]=dp[i][0][1]=dp[i][1][0]=dp[i][1][1]=0;
	  }
}
void getdp()
{
	long long i;
	for(i=1;i<cz;i++)
	  {
	  	if(nxt[i]==1)
	  	  {
	  	  	dp[i+1][0][0]=(dp[i][0][0]+dp[i][1][0])%mod;
	  	  	dp[i+1][1][0]=(dp[i][0][0]+dp[i][1][1])%mod;
	  	  	dp[i+1][0][1]=(dp[i][0][1]+dp[i][1][1])%mod;
	  	  	dp[i+1][1][1]=(dp[i][0][1]+dp[i][1][0])%mod;
		  }
		if(nxt[i]==2)
		  {
	  	  	dp[i+1][0][0]=(dp[i][1][0]+dp[i][0][1])%mod;
	  	  	dp[i+1][1][0]=(dp[i][0][1]+dp[i][1][1])%mod;
	  	  	dp[i+1][0][1]=(dp[i][1][1]+dp[i][0][0])%mod;
	  	  	dp[i+1][1][1]=(dp[i][0][0]+dp[i][1][0])%mod;
		  }
	  }
}
void getans(long long pos)
{
	if(k[pos]==0)
	  return;
	getcir(pos);
//	for(int i=1;i<=cz;i++)
//	  printf("%lld ",z[i]);
//	printf("\n");
	if(cz==1)
	  {
	  	cnt++;
	  	if(k[pos]==1)
	  	{
	  	tim[cnt][0]=1;
	  	tim[cnt][1]=1;
	  	}
	  	else
	  	{
	  		if(abs(a[pos][1])==abs(a[pos][2]))
	  		  {
	  		  	if(a[pos][1]==a[pos][2])
	  		  	  tim[cnt][0]=2,tim[cnt][1]=0;
	  		  	else
	  		  	  tim[cnt][0]=0,tim[cnt][1]=2;
			  }
			else
			  {
			  	tim[cnt][0]=tim[cnt][1]=2;
			  }
		}
	  	return;
	  }
	cldp(cz);
	dp[1][0][0]=1;
	getdp();
	if(!nxt[cz])
	  {
		cldp(cz);
		dp[1][0][0]=1;
	  	if(k[z[1]]==2)
	  	  {
	  	  	dp[1][0][0]=dp[1][1][1]=1;
		  }
		getdp();
//		for(int  i=1;i<=cz;i++)
//		  {
//		  	printf("%lld %lld %lld %lld\n",dp[i][0][0],dp[i][0][1],dp[i][1][0],dp[i][1][1]);
//		  }
//		printf("\n");
	  	cnt++;
	  	if(k[z[cz]]==1)
	  	  {
	  	    tim[cnt][0]=(dp[cz][0][0]+dp[cz][1][0])%mod;
	  	    tim[cnt][1]=(dp[cz][0][1]+dp[cz][1][1])%mod;
		  }
		else
		  {
		  	tim[cnt][0]=(dp[cz][0][0]+dp[cz][0][1]+dp[cz][1][0]*2)%mod;
		  	tim[cnt][1]=(dp[cz][0][1]+dp[cz][0][0]+dp[cz][1][1]*2)%mod;
		  }
	  }
	else
	  {
	  	cnt++;
	  	tim[cnt][0]=tim[cnt][1]=0;
	  	if(nxt[cz]==1)
	  	  {
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][0][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][0][1]+dp[cz][1][1])%mod;
	  		cldp(cz);
	  		dp[1][1][1]=1;
	  		getdp();
	  		dp[cz][1][0]=(dp[cz][1][0]+dp[cz][0][1])%mod;
	  		dp[cz][1][1]=(dp[cz][1][1]+dp[cz][0][0])%mod;
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][1][1])%mod;
		  }
		else
		  {
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][1][1])%mod;
	  		cldp(cz);
	  		dp[1][1][1]=1;
	  		getdp();
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][0][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][0][1])%mod;
		  }
	  }
}
int main()
{
	long long n,m,i,j,jd;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)
	  {
	  	scanf("%lld",&k[i]);
	  	for(j=1;j<=k[i];j++)
	  	  {
	  	  	scanf("%lld",&a[i][j]);
	  	  	jd=abs(a[i][j]);
	  	  	cc[jd]++;
	  	  	if(a[i][j]>0)
	  	  	  mp[jd][cc[jd]]=i;
	  	  	else
	  	  	  mp[jd][cc[jd]]=-i;
		  }
	  }
	for(i=1;i<=n;i++)
	  head[i]=-1;
	for(i=1;i<=m;i++)
	if(cc[i]==2)
	  {
	  	adde(mp[i][1],mp[i][2]);
	  	adde(mp[i][2],mp[i][1]);
//	  	printf("%lld %lld\n",mp[i][1],mp[i][2]);
	  }
	for(i=1;i<=n;i++)
	  vis[i]=1,vis1[i]=1;
	for(i=1;i<=n;i++)
	  if(vis[i])
	    {
	    	getans(i);
		}
//	for(i=1;i<=cnt;i++)
//	  printf("%lld %lld\n",tim[i][0],tim[i][1]);
	long long ans0=1,ans1=0,l0,l1;
	for(i=1;i<=cnt;i++)
	  {
	  	l0=ans0,l1=ans1;
	  	ans0=(l0*tim[i][0]+l1*tim[i][1])%mod;
	  	ans1=(l0*tim[i][1]+l1*tim[i][0])%mod;
	  }
	printf("%lld\n",ans1);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long mod=1e9+7;
struct node{
	long long fr,tt,lab;
};
node s[1000005];
long long cnte=0,head[1000005];
bool vis[1000005];
bool vis1[1000005];
long long nxt[1000005];
long long dp[1000005][2][2];
long long k[1000005],a[1000005][2],mp[1000005][2],cc[1000005];
long long cnt=0,tim[1000005][2];
void adde(long long a,long long b)
{
	s[cnte].fr=head[abs(a)];
	head[abs(a)]=cnte;
	s[cnte].tt=abs(b);
	if((a>0)!=(b>0))
	  s[cnte].lab=2;
	else
	  s[cnte].lab=1;
	cnte++;
}
long long cnt_st=0,st[1000005];
long long getst(long long pos)
{
	long long np,i;
	cnt_st=1;
	st[cnt_st]=pos;
	np=pos;
	while(vis1[np])
	{
	vis1[np]=0;
	for(i=head[np];i!=-1;i=s[i].fr)
	  {
	  	if(vis1[s[i].tt])
	  	  {
	  	  	cnt_st++;
	  	  	st[cnt_st]=s[i].tt;
	  	  	np=s[i].tt;
	  	  	break;
		  }
	  }
	}
	return st[cnt_st];
}
long long cz,z[1000005];
void getcir(long long pos)
{
	long long i;
	long long st,np;
	cz=0;
	st=getst(pos);

	cz++,z[cz]=st;
	np=st;
	int t1=0;
	while(vis[np])
	{
	vis[np]=0;
	for(i=head[np];i!=-1;i=s[i].fr)
	  if(vis[s[i].tt])
	    {
	    	if(np==z[1])
	    	  t1=i;
	    	nxt[cz]=s[i].lab;
	    	cz++;

	    	z[cz]=nxt[cz]=0;

	    	z[cz]=s[i].tt;
	    	np=s[i].tt;
	    	break;
		}
	}
	for(i=head[z[1]];i!=-1;i=s[i].fr)
	  if(s[i].tt==z[cz]&&i!=t1)
	    nxt[cz]=s[i].lab;
//	for(i=1;i<=cz;i++)
//	  printf("%lld %lld\n",z[i],nxt[i]);
}
void cldp(long long n)
{
	long long i;
	for(i=1;i<=n;i++)
	  {
	  	dp[i][0][0]=dp[i][0][1]=dp[i][1][0]=dp[i][1][1]=0;
	  }
}
void getdp()
{
	long long i;
	for(i=1;i<cz;i++)
	  {
	  	if(nxt[i]==1)
	  	  {
	  	  	dp[i+1][0][0]=(dp[i][0][0]+dp[i][1][0])%mod;
	  	  	dp[i+1][1][0]=(dp[i][0][0]+dp[i][1][1])%mod;
	  	  	dp[i+1][0][1]=(dp[i][0][1]+dp[i][1][1])%mod;
	  	  	dp[i+1][1][1]=(dp[i][0][1]+dp[i][1][0])%mod;
		  }
		if(nxt[i]==2)
		  {
	  	  	dp[i+1][0][0]=(dp[i][1][0]+dp[i][0][1])%mod;
	  	  	dp[i+1][1][0]=(dp[i][0][1]+dp[i][1][1])%mod;
	  	  	dp[i+1][0][1]=(dp[i][1][1]+dp[i][0][0])%mod;
	  	  	dp[i+1][1][1]=(dp[i][0][0]+dp[i][1][0])%mod;
		  }
	  }
}
void getans(long long pos)
{
	if(k[pos]==0)
	  return;
	getcir(pos);
//	for(int i=1;i<=cz;i++)
//	  printf("%lld ",z[i]);
//	printf("\n");
	if(cz==1)
	  {
	  	cnt++;
	  	if(k[pos]==1)
	  	{
	  	tim[cnt][0]=1;
	  	tim[cnt][1]=1;
	  	}
	  	else
	  	{
	  		if(abs(a[pos][1])==abs(a[pos][2]))
	  		  {
	  		  	if(a[pos][1]==a[pos][2])
	  		  	  tim[cnt][0]=2,tim[cnt][1]=0;
	  		  	else
	  		  	  tim[cnt][0]=0,tim[cnt][1]=2;
			  }
			else
			  {
			  	tim[cnt][0]=tim[cnt][1]=2;
			  }
		}
	  	return;
	  }
	cldp(cz);
	dp[1][0][0]=1;
	getdp();
	if(!nxt[cz])
	  {
		cldp(cz);
		dp[1][0][0]=1;
	  	if(k[z[1]]==2)
	  	  {
	  	  	dp[1][0][0]=dp[1][1][1]=1;
		  }
		getdp();
//		for(int  i=1;i<=cz;i++)
//		  {
//		  	printf("%lld %lld %lld %lld\n",dp[i][0][0],dp[i][0][1],dp[i][1][0],dp[i][1][1]);
//		  }
//		printf("\n");
	  	cnt++;
	  	if(k[z[cz]]==1)
	  	  {
	  	    tim[cnt][0]=(dp[cz][0][0]+dp[cz][1][0])%mod;
	  	    tim[cnt][1]=(dp[cz][0][1]+dp[cz][1][1])%mod;
		  }
		else
		  {
		  	tim[cnt][0]=(dp[cz][0][0]+dp[cz][0][1]+dp[cz][1][0]*2)%mod;
		  	tim[cnt][1]=(dp[cz][0][1]+dp[cz][0][0]+dp[cz][1][1]*2)%mod;
		  }
	  }
	else
	  {
	  	cnt++;
	  	tim[cnt][0]=tim[cnt][1]=0;
	  	if(nxt[cz]==1)
	  	  {
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][0][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][0][1]+dp[cz][1][1])%mod;
	  		cldp(cz);
	  		dp[1][1][1]=1;
	  		getdp();
	  		dp[cz][1][0]=(dp[cz][1][0]+dp[cz][0][1])%mod;
	  		dp[cz][1][1]=(dp[cz][1][1]+dp[cz][0][0])%mod;
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][1][1])%mod;
		  }
		else
		  {
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][1][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][1][1])%mod;
	  		cldp(cz);
	  		dp[1][1][1]=1;
	  		getdp();
	  		tim[cnt][0]=(tim[cnt][0]+dp[cz][0][0])%mod;
	  		tim[cnt][1]=(tim[cnt][1]+dp[cz][0][1])%mod;
		  }
	  }
}
bool ll[1000005];
int main()
{
	long long n,m,i,j,jd;
	scanf("%lld%lld",&n,&m);
	for(i=1;i<=m;i++)
	  ll[i]=1;
	for(i=1;i<=n;i++)
	  {
	  	scanf("%lld",&k[i]);
	  	for(j=1;j<=k[i];j++)
	  	  {
	  	  	scanf("%lld",&a[i][j]);
	  	  	jd=abs(a[i][j]);
	  	  	ll[jd]=0;
	  	  	cc[jd]++;
	  	  	if(a[i][j]>0)
	  	  	  mp[jd][cc[jd]]=i;
	  	  	else
	  	  	  mp[jd][cc[jd]]=-i;
		  }
	  }
	for(i=1;i<=n;i++)
	  head[i]=-1;
	for(i=1;i<=m;i++)
	if(cc[i]==2)
	  {
	  	adde(mp[i][1],mp[i][2]);
	  	adde(mp[i][2],mp[i][1]);
//	  	printf("%lld %lld\n",mp[i][1],mp[i][2]);
	  }
	for(i=1;i<=n;i++)
	  vis[i]=1,vis1[i]=1;
	for(i=1;i<=n;i++)
	  if(vis[i])
	    {
	    	getans(i);
		}
//	for(i=1;i<=cnt;i++)
//	  printf("%lld %lld\n",tim[i][0],tim[i][1]);
	long long ans0=1,ans1=0,l0,l1;
	for(i=1;i<=cnt;i++)
	  {
	  	l0=ans0,l1=ans1;
	  	ans0=(l0*tim[i][0]+l1*tim[i][1])%mod;
	  	ans1=(l0*tim[i][1]+l1*tim[i][0])%mod;
	  }
	for(i=1;i<=m;i++)
	  if(ll[i])
	    ans1=(ans1*2)%mod;
	printf("%lld\n",ans1);
	return 0;
}