Logical Tree#5206

Logical Tree

1 second
64 megabytes
Very easy

Let's consider a type of binary tree called a logical tree. In this tree, each level is completely filled except possibly the last (deepest) level, where all nodes are as far left as possible. Each node in the tree has either zero or two children.

Each node is associated with a logical value, either or . Additionally, each internal node has a logical operation ("AND" or "OR") associated with it. The value of an "AND" node is the logical AND of the values of its children; the value of an "OR" node is the logical OR of the values of its children. The values of all leaf nodes are given in the input, so the value of every node in the tree can be determined.

Our primary interest is the value at the root node. We want the root to have a specified logical value , which may differ from its initial value. Fortunately, it is possible to change the logical operation (swap "AND" and "OR") at some internal nodes.

Given the structure of the logical tree and a specification of the internal nodes whose operations can be changed, determine the minimum number of changes required so that the root's value becomes . If it is impossible, output the string IMPOSSIBLE (without quotes).

Input

The first line contains two numbers and (1 \leq n \leq 10000, 0 \leq v \leq 1): the number of nodes in the tree and the desired root value, respectively. Since every node has either zero or two children, is odd. The next lines describe the nodes of the tree. Nodes are numbered from to .

The first \frac{n-1}{2} lines describe the internal nodes. Each such line contains two integers and (each or ):

  • g = 1 means the node's operation is "AND"; g = 0 means "OR".

  • c = 1 means the operation at this node can be changed (between "AND" and "OR"); c=0 means it cannot be changed.

The internal node numbered has children and 2i+1.

The following \frac{n+1}{2} lines describe the leaves. Each line contains a single integer, or , which is the value of the corresponding leaf node.

Output

Output the answer to the problem. If it is impossible to achieve the desired root value, output IMPOSSIBLE.

Examples

Example 1

Loading
Loading