#P1395C. Boboniu and Bit Operations

    ID: 1313 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>bitmasksbrute forcedpgreedy*1600

Boboniu and Bit Operations

No submission language available for this problem.

Description

Boboniu likes bit operations. He wants to play a game with you.

Boboniu gives you two sequences of non-negative integers a1,a2,,ana_1,a_2,\ldots,a_n and b1,b2,,bmb_1,b_2,\ldots,b_m.

For each ii (1in1\le i\le n), you're asked to choose a jj (1jm1\le j\le m) and let ci=ai&bjc_i=a_i\& b_j, where &\& denotes the bitwise AND operation. Note that you can pick the same jj for different ii's.

Find the minimum possible c1c2cnc_1 | c_2 | \ldots | c_n, where | denotes the bitwise OR operation.

The first line contains two integers nn and mm (1n,m2001\le n,m\le 200).

The next line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (0ai<290\le a_i < 2^9).

The next line contains mm integers b1,b2,,bmb_1,b_2,\ldots,b_m (0bi<290\le b_i < 2^9).

Print one integer: the minimum possible c1c2cnc_1 | c_2 | \ldots | c_n.

Input

The first line contains two integers nn and mm (1n,m2001\le n,m\le 200).

The next line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (0ai<290\le a_i < 2^9).

The next line contains mm integers b1,b2,,bmb_1,b_2,\ldots,b_m (0bi<290\le b_i < 2^9).

Output

Print one integer: the minimum possible c1c2cnc_1 | c_2 | \ldots | c_n.

Samples

Sample Input 1

4 2
2 6 4 0
2 4

Sample Output 1

2

Sample Input 2

7 6
1 9 1 9 8 1 0
1 1 4 5 1 4

Sample Output 2

0

Sample Input 3

8 5
179 261 432 162 82 43 10 38
379 357 202 184 197

Sample Output 3

147

Note

For the first example, we have c1=a1&b2=0c_1=a_1\& b_2=0, c2=a2&b1=2c_2=a_2\& b_1=2, c3=a3&b1=0c_3=a_3\& b_1=0, c4=a4&b1=0c_4 = a_4\& b_1=0.Thus c1c2c3c4=2c_1 | c_2 | c_3 |c_4 =2, and this is the minimal answer we can get.