2-SAT Satisfiability

No attempts yetTime limit1sMemory limit256 MB

Problem

2-SAT asks how to pick a value for each of the boolean variables x1,x2,,xNx_1, x_2, \ldots, x_N so that a 2-CNF formula becomes true.

A 2-CNF formula looks like (xy)(¬yz)(x¬z)(zy)(x \lor y) \land (\lnot y \lor z) \land (x \lor \lnot z) \land (z \lor y). Each parenthesized part is a clause, and a clause joins two variables with \lor. Here \lor is OR, \land is AND, and ¬\lnot is NOT.

You are given the number of variables NN, the number of clauses MM, and the formula ff. Write a program that decides whether ff can be made true.

For example, take N=3N = 3, M=4M = 4, and f=(¬x1x2)(¬x2x3)(x1x3)(x3x2)f = (\lnot x_1 \lor x_2) \land (\lnot x_2 \lor x_3) \land (x_1 \lor x_3) \land (x_3 \lor x_2). Setting x1x_1 to false, x2x_2 to false, and x3x_3 to true makes ff true. For N=1N = 1, M=2M = 2, and f=(x1x1)(¬x1¬x1)f = (x_1 \lor x_1) \land (\lnot x_1 \lor \lnot x_1), no value of x1x_1 makes ff true.

Input

The first line holds the number of variables NN (1N100001 \le N \le 10000) and the number of clauses MM (1M1000001 \le M \le 100000). Each of the next MM lines holds one clause as two integers ii and jj (1i,jN1 \le |i|, |j| \le N). A positive ii means xix_i and a negative ii means ¬xi\lnot x_{-i}. The same rule applies to jj.

Output

Print 1 on the first line if ff can be made true, and 0 otherwise.