Boboniu and Bit Operations

TimeLimit:1000MS  MemoryLimit:256MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
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,…,an and b1,b2,…,bm.


For each i (1≤i≤n), you're asked to choose a j (1≤j≤m) and let ci=ai&bj, where & denotes the bitwise AND operation. Note that you can pick the same j for different i's.


Find the minimum possible c1|c2|…|cn, where | denotes the bitwise OR operation.


Input

The first line contains two integers n and m (1≤n,m≤200).


The next line contains n integers a1,a2,…,an (0≤ai<2^9).


The next line contains m integers b1,b2,…,bm (0≤bi<2^9).


Output

Print one integer: the minimum possible c1|c2|…|cn

SampleInput 1
4 2
2 6 4 0
2 4
SampleOutput 1
2
SampleInput 2
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
SampleOutput 2
0
SampleInput 3
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
SampleOutput 3
147
Note
For the first example, we have c1=a1&b2=0, c2=a2&b1=2, c3=a3&b1=0, c4=a4&b1=0.Thus c1|c2|c3|c4=2, and this is the minimal answer we can get.

Submit
题目统计信息详细
总AC数5
通过人数5
尝试人数5
总提交量6
AC率83.33%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: