Adin was recently asked whether he would like to “build muscles or build eagers”. He knew how building muscles would help him, but he had to search the internet to learn about building eagers.
It turns out that there is an array of integers, , called the eager coefficients. Adin wants to split the array into exactly contiguous, non-empty subarrays. To do this, he chooses split points to divide the array.
Formally, we can define the partition by choosing indices such that . The -th subarray then consists of the elements from index to (where and ).
Let be the bitwise OR of all elements in the -th subarray. The final amount of eagers is calculated as the bitwise AND of these subarray values:
To truly answer the question, Adin wants to find the maximum possible value for among all valid partitions into subarrays. Write a program, eagers, that calculates this value for him.
A subarray is a contiguous sequence of elements from the original array. For example, is a subarray of , but is not.
A bitwise OR (|) is a binary operation that compares two numbers in binary representation, bit by bit. It returns a for each position if both corresponding bits are , and otherwise. For example, .
A bitwise AND is a binary operation that compares two numbers in binary representation, bit by bit. It returns a for each position if both corresponding bits are , and otherwise. For example, .
Input data
On one line of standard input the positive integers and are given. On the next line positive integers are given.
Output data
On standard output print one number – the maximum possible value for among all possible splits.
Restrictions
| Subtask | Points | Required subtasks | Other constraints | ||
|---|---|---|---|---|---|
| 0 | 0 | The examples. | |||
| 1 | 12 | ||||
| 2 | 2 | ||||
| 3 | 13 | ||||
| 4 | 15 | ||||
| 5 | 11 | ||||
| 6 | 12 | ||||
| 7 | 13 | ||||
| 8 | 22 |
Example 1
stdin
7 3
2 1 4 3 2 2 5
stdout
3
Explanation
One of the optimal solutions is to split into the subarrays . Their respective values are . The BITWISE AND of the numbers is exactly .
Example 2
stdin
6 2
1 0 0 1 2 2
stdout
2
Explanation
The only optimal solution is to split into the subarrays and . Their respective values are and , which give a BITWISE AND of .