2-SAT asks whether boolean variables x1,x2,…,xN can be assigned values that make a 2-CNF formula true.
A 2-CNF formula looks like (x∨y)∧(¬y∨z)∧(x∨¬z)∧(z∨y). Each parenthesized part is a clause, and a clause is two variables joined by ∨. Here ∨ is OR, ∧ is AND, and ¬ is NOT.
Given the number of variables N, the number of clauses M, and the formula f, write a program that decides whether f can be made true.
For example, take N=3, M=4, and f=(¬x1∨x2)∧(¬x2∨x3)∧(x1∨x3)∧(x3∨x2). Setting x1 to false, x2 to false, and x3 to true makes f true. With N=1, M=2, and f=(x1∨x1)∧(¬x1∨¬x1), no value of x1 makes f true.
The first line has the number of variables N (1≤N≤20) and the number of clauses M (1≤M≤100). Each of the next M lines has one clause, given as two integers i and j (1≤∣i∣,∣j∣≤N). A positive integer means xi or xj, and a negative integer means ¬x−i or ¬x−j.
Print 1 on the first line if f can be made true, and 0 otherwise.