Natalia Romanova is trying to test something on the new gun S.H.I.E.L.D gave her. In order to determine the result of the test, she needs to find the number of answers to a certain equation. The equation is of form:

<image>

Where <image> represents logical OR and <image> represents logical exclusive OR (XOR), and vi, j are some boolean variables or their negations. Natalia calls the left side of the equation a XNF formula. Each statement in brackets is called a clause, and vi, j are called literals.

In the equation Natalia has, the left side is actually a 2-XNF-2 containing variables x1, x2, ..., xm and their negations. An XNF formula is 2-XNF-2 if:

  1. For each 1 ≤ i ≤ n, ki ≤ 2, i.e. the size of each clause doesn't exceed two. 
  2. Each variable occurs in the formula at most two times (with negation and without negation in total). Please note that it's possible that a variable occurs twice but its negation doesn't occur in any clause (or vice versa). 



Natalia is given a formula of m variables, consisting of n clauses. Please, make sure to check the samples in order to properly understand how the formula looks like.

Natalia is more into fight than theory, so she asked you to tell her the number of answers to this equation. More precisely, you need to find the number of ways to set x1, ..., xm with true and false (out of total of 2m ways) so that the equation is satisfied. Since this number can be extremely large, you need to print the answer modulo 109 + 7.

Please, note that some variable may appear twice in one clause, or not appear in the equation at all (but still, setting it to false or true gives different ways to set variables).

Input

The first line of input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of clauses and the number of variables respectively.

The next n lines contain the formula. The i-th of them starts with an integer ki — the number of literals in the i-th clause. It is followed by ki non-zero integers ai, 1, ..., ai, ki. If ai, j > 0 then vi, j is xai, j otherwise it's negation of x - ai, j (1 ≤ ki ≤ 2,  - m ≤ ai, j ≤ m, ai, j ≠ 0).

Output

Print the answer modulo 1 000 000 007 (109 + 7) in one line.

Examples

Input

6 7
2 4 -2
2 6 3
2 -7 1
2 -5 1
2 3 6
2 -2 -5


Output

48


Input

8 10
1 -5
2 4 -6
2 -2 -6
2 -7 9
2 10 -1
2 3 -1
2 -8 9
2 5 8


Output

544


Input

2 3
2 1 1
2 -3 3


Output

4

Note

The equation in the first sample is:

<image>

The equation in the second sample is:

<image>

The equation in the third sample is:

<image>
import java.io.*;
import java.util.*;

public class C {

	static final int P = 1_000_000_007;
	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	static class Edge {
		int from, to;

		int signFrom, signTo, id;

		public Edge(int signFrom, int signTo, int id) {
			this.signFrom = signFrom;
			this.signTo = signTo;
			this.id = id;
			from = Math.abs(signFrom);
			to = Math.abs(signTo);
		}

	}

	int eval(int x, int y, int signX, int signY) {
		return ((x == 0) == (signX < 0)) || ((y == 0) == (signY < 0)) ? 1 : 0;
	}

	int solve(int m, int n, int[][] a) {
		int rhs = 1;

		List<Edge>[] g;
		g = new List[n + 1];
		for (int i = 1; i <= n; i++) {
			g[i] = new ArrayList<>(2);
		}

		boolean[] inLhs = new boolean[n + 1];

		for (int i = 0; i < m; i++) {
			int k = a[i].length;
			int[] tmp = a[i];
			if (k == 2 && tmp[0] == tmp[1]) {
				k = 1;
				tmp = new int[] { tmp[0] };
			}
			if (k == 2 && tmp[0] == -tmp[1]) {
				rhs ^= 1;
				continue;
			}

			// System.err.println(tmp[0] + " " + tmp[1]);

			if (k == 2) {
				g[Math.abs(tmp[0])].add(new Edge(tmp[0], tmp[1], i));
				g[Math.abs(tmp[1])].add(new Edge(tmp[1], tmp[0], i));
			} else {
				inLhs[Math.abs(tmp[0])] ^= true;
				if (tmp[0] < 0) {
					rhs ^= 1;
				}
			}
		}

		int[] ret = { 1, 0 };

		boolean[] vis = new boolean[n + 1];
		for (int i = 1; i <= n; i++) {
			if (!vis[i] && g[i].size() == 1) {

				int[][][] dp = new int[2][2][2]; // first, last, value
				dp[0][0][0]++;
				dp[1][1][inLhs[i] ? 1 : 0]++;

				vis[i] = true;
				int v = i;
				Edge e = g[v].get(0);
				while (true) {
					int u = e.to;
					vis[u] = true;

					int signU = e.signTo;
					int signV = e.signFrom;

					int[][][] nxt = new int[2][2][2];

					for (int first = 0; first < 2; first++)
						for (int prev = 0; prev < 2; prev++)
							for (int value = 0; value < 2; value++) {
								for (int now = 0; now < 2; now++) {

									int newValue = value
											^ ((inLhs[u] && now == 1) ? 1 : 0)
											^ eval(prev, now, signV, signU);

									nxt[first][now][newValue] += dp[first][prev][value];
									nxt[first][now][newValue] %= P;
								}
							}

					dp = nxt;

					if (g[u].size() == 1) {
						break;
					}

					Edge newE = g[u].get(g[u].get(0).id == e.id ? 1 : 0);

					v = u;
					e = newE;
				}

				int[] ways = new int[2];
				for (int first = 0; first < 2; first++)
					for (int last = 0; last < 2; last++)
						for (int value = 0; value < 2; value++) {
							ways[value] += dp[first][last][value];
							ways[value] %= P;
						}

				int[] newRet = new int[2];
				for (int was = 0; was < 2; was++)
					for (int now = 0; now < 2; now++) {
						newRet[(was + now) % 2] += (int) ((long) ret[was]
								* ways[now] % P);
						newRet[(was + now) % 2] %= P;
					}

				ret = newRet;
			}
		}
		
//		System.err.println(Arrays.toString(ret));
//		System.err.println(rhs);
//		System.err.println(Arrays.toString(inLhs));

		for (int i = 1; i <= n; i++) {
			if (!vis[i] && g[i].size() == 2) {

				int[][][] dp = new int[2][2][2]; // first, last, value
				dp[0][0][0]++;
				dp[1][1][inLhs[i] ? 1 : 0]++;

				vis[i] = true;
				int v = i;
				Edge e = g[v].get(0);
				while (true) {
					int u = e.to;
					if (u == i) {
						break;
					}
					vis[u] = true;

					int signU = e.signTo;
					int signV = e.signFrom;

					int[][][] nxt = new int[2][2][2];

					for (int first = 0; first < 2; first++)
						for (int prev = 0; prev < 2; prev++)
							for (int value = 0; value < 2; value++) {
								for (int now = 0; now < 2; now++) {

									int newValue = value
											^ (inLhs[u] && now == 1 ? 1 : 0)
											^ eval(prev, now, signV, signU);

									nxt[first][now][newValue] += dp[first][prev][value];
									nxt[first][now][newValue] %= P;
								}
							}

					dp = nxt;

					if (g[u].size() == 1) {
						throw new AssertionError();
					}

					Edge newE = g[u].get(g[u].get(0).id == e.id ? 1 : 0);

					v = u;
					e = newE;
				}

				int[][][] nxt = new int[2][2][2];

				for (int first = 0; first < 2; first++)
					for (int last = 0; last < 2; last++)
						for (int value = 0; value < 2; value++) {

							int newValue = value
									^ eval(last, first, e.signFrom, e.signTo);

							nxt[first][last][newValue] += dp[first][last][value];
							nxt[first][last][newValue] %= P;
						}

				dp = nxt;

				int[] ways = new int[2];
				for (int first = 0; first < 2; first++)
					for (int last = 0; last < 2; last++)
						for (int value = 0; value < 2; value++) {
							ways[value] += dp[first][last][value];
							ways[value] %= P;
						}

				int[] newRet = new int[2];
				for (int was = 0; was < 2; was++)
					for (int now = 0; now < 2; now++) {
						newRet[(was + now) % 2] += (int) ((long) ret[was]
								* ways[now] % P);
						newRet[(was + now) % 2] %= P;
					}

				ret = newRet;
			}
		}

		for (int i = 1; i <= n; i++) {
			if (g[i].isEmpty()) {
				int[] newRet = new int[2];
				for (int was = 0; was < 2; was++)
					for (int now = 0; now < 2; now++) {

						int newIdx = (was + ((now == 1 && inLhs[i]) ? 1 : 0)) % 2;
						newRet[newIdx] += ret[was];
						newRet[newIdx] %= P;
					}

				ret = newRet;
			}
		}

		return ret[rhs];
	}

	int brute(int m, int n, int[][] a) {
		int ret = 0;
		for (int mask = 0; mask < 1 << n; mask++) {
			int cur = 0;
			outer: for (int i = 0; i < m; i++) {
				for (int j = 0; j < a[i].length; j++) {
					int have = get(mask, Math.abs(a[i][j]) - 1);
					int need = a[i][j] < 0 ? 0 : 1;
					if (have == need) {
						cur ^= 1;
						continue outer;
					}
				}
			}
			if (cur == 1) {
				ret++;
			}
		}
		return ret;
	}
	
	int get(int mask, int i) {
		return (mask >> i) & 1;
	}
	
	Random rng = new Random();
	
	void oneTest(int n) throws IOException {
		int m = rng.nextInt(n);
		int[] cnt = new int[n];
		int[][] a = new int[m][];
		for (int i = 0; i < m; i++) {
			int k = rng.nextInt(2) + 1;
			a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				int idx;
				do {
					idx = rng.nextInt(n);
				} while (cnt[idx] == 2);
				cnt[idx]++;
				a[i][j] = (idx + 1) * (rng.nextBoolean() ? -1 : 1);
			}
		}
		
		System.err.println(m + " " + n + " " + Arrays.deepToString(a));
		
		int wrong = solve(m, n, a);
		int slow = brute(m, n, a);
		if (wrong != slow) {
			throw new AssertionError(m + " " + n + " " + Arrays.deepToString(a));
		}
	}

	C() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		int m = nextInt();
		int n = nextInt();
		int[][] a = new int[m][];
		for (int i = 0; i < m; i++) {
			int k = nextInt();
			a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				a[i][j] = nextInt();
			}
		}
		out.println(solve(m, n, a));
//		out.println(brute(m, n, a));
		out.close();
		
//		while (true) {
//			oneTest(4);
//		}
	}

	public static void main(String[] args) throws IOException {
		new C();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}