Azugand, the city from the famous Prahovand Valley, is known for its peculiar structure: it has intersections, numbered from to , all of which have an assigned value . Two distinct intersections have a street between them if and only if the bitwise AND (represented as ) of their values is non-zero.
Formally, you are given a graph with vertices, each vertex having a value assigned to it. We have an edge between two distinct vertices and iff .
Task
Andrei, a well-known child from the valley, wants to make a table with the shortest distances between two points of interest, but he is overwhelmed by the number of queries he wants to solve, so he asks for your help! You are given queries, in which you have to compute . We define as the minimum number of edges that are in the shortest path in the graph between vertices and . If we can’t reach vertex from vertex , then the value of is .
Input data
The first line of input contains two integers and , the number of vertices in the graph, and the number of queries, respectively.
The next line contains integers , the values assigned to the vertices of the graph.
Each of the next lines of the input contains two distinct integers and , the vertices for which you must compute .
Output data
Print integers, each one on a separate line: the value of for each query.
Constraints and clarifications
- for each
- for each
# | Points | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 7 | , |
3 | 23 | |
4 | 21 | for each |
5 | 49 | No additional constraints |
Example 1
stdin
4 4
9 3 16 6
1 2
2 4
4 1
2 3
stdout
1
1
2
-1
Explanation
In the first query, and , , so there is an edge between vertices and , so the minimum distance is .
In the second query, and , , so there is an edge between vertices and , so the minimum distance is .
In the third query, and , , so there is no edge between vertices and , so the minimum distance is at least . For the path the values are respectively which means that there is an edge between vertices and also between and , so there is a path of length between vertices and .
In the fourth query, , and , which means that there are no edges connected to vertex , so there is no path between vertices and .
Example 2
stdin
7 5
3072 5120 67584 73728 49152 24576 40960
2 5
7 3
1 6
5 6
7 2
stdout
5
2
3
1
4