Bitwise Exclusive-OR Sequence
题号:NC230851
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

AAA has a nonnegative integer sequence with m constraints, each of which is described as , where denotes the bitwise exclusive-OR operation.

More precisely, the bitwise exclusive-OR operation is a binary operation which is equivalent to applying logical exclusive-OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the respective positions in the operands are different. For example, if and , then .

Now AAA wants to find out the minimum sum of all the elements in the sequence, or determine that the sequence meets all the constraints does not exist.

输入描述:

The first line contains two integers n  and m , denoting the length of sequence and the number of conditions.

The follow m lines, each of which contains three integers u, v and w , indicating a constraint that .

输出描述:

Output a line containing a single integer, indicating the minimum sum of all the elements in the sequence or -1 if the sequence meets all the constraints does not exist.
示例1

输入

复制
3 2
1 2 1
2 3 1

输出

复制
1

说明

In the first sample case, the sequence [a_1,a_2,a_3]=[0,1,0] meets all the constraints and has the minimum sum of all the elements.