import std.stdio, std.math;

void main(){
	int n, m;
	immutable mod = cast(long)(1e9 + 7);
	scanf("%d%d", &n, &m);

	auto Cs = new int[][](m,2), idxToC = new int[][](n+1, 2);
	auto appear = new int[](n+1);
	foreach(i; 0..m){
		scanf("%d%d", &Cs[i][0], &Cs[i][1]);
		foreach(j; 0..2){
			int x = abs(Cs[i][j]);
			idxToC[x][++appear[x]-1] = i;
		}
	}

	int getAnother(int x, int c){
		return idxToC[x][idxToC[x][0] == c ? 1 : 0];
	}

	long ans = 1;
	auto visited = new bool[](m);
	//single
	foreach(i; 0..m)if(!visited[i]){
		if( abs(Cs[i][0]) == abs(Cs[i][1]) ){
			visited[i] = true;
			ans = ans * (Cs[i][0] == Cs[i][1] ? 1 : 2) % mod;
		}
	}

	void calcDp(int len, long[][] dp, bool[] same){
		foreach(i; 0..len){
			dp[i+1][0] = dp[i][same[i] ? 1 : 0];
			dp[i+1][1] = (dp[i][0] + dp[i][1]) % mod;
		}
	}

	//line
	foreach(i; 1..n+1)if(appear[i] == 1){
		int idx = idxToC[i][0], x = i, y = Cs[idx][abs(Cs[idx][0]) == x ? 1 : 0];
		if(visited[idx]) continue;
		visited[idx] = true;
		bool[] same;
		for(;appear[abs(y)] == 2;){
			int nextIdx = getAnother(abs(y), idx);
			int which = abs(Cs[nextIdx][0]) == abs(y) ? 0 : 1;
			int nx = Cs[nextIdx][which], ny = Cs[nextIdx][which^1];
			same ~= y == nx;
			visited[nextIdx] = true;
			x = nx; y = ny; idx = nextIdx;
		}

		auto dp = new long[][](same.length+1, 2);
		dp[0][0] = 1;
		dp[0][1] = 2;
		calcDp(cast(int)same.length, dp, same);
		ans = ans * (dp[$-1][0] + dp[$-1][1]) % mod;
	}

	//cycle
	foreach(i; 0..m)if(!visited[i]){
		int idx = i, x = Cs[i][0], y = Cs[i][1];
		bool[] same;
		visited[idx] = true;
		for(;;){
			int nextIdx = getAnother(abs(y), idx);
			int which = abs(Cs[nextIdx][0]) == abs(y) ? 0 : 1;
			int nx = Cs[nextIdx][which], ny = Cs[nextIdx][which^1];
			same ~= y == nx;
			if(visited[nextIdx]){
				break;
			}
			visited[nextIdx] = true;
			x = nx; y = ny; idx = nextIdx;
		}

		long tmp = 0;
		auto dp = new long[][](same.length, 2);
		dp[0][0] = dp[0][1] = 1;
		calcDp(cast(int)same.length-1, dp, same);
		tmp += dp[$-1][same[$-1] ? 1 : 0];

		dp[0][0] = 0; dp[0][1] = 1;
		calcDp(cast(int)same.length-1, dp, same);
		tmp += dp[$-1][same[$-1] ? 0 : 1];

		ans = ans * tmp % mod;
	}

	writeln(ans);
}