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

Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.

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

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


-----Input-----

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

The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).

The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).


-----Output-----

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


-----Examples-----
Input
4 2
2 6 4 0
2 4

Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4

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

Output
147


-----Note-----

For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get.

Difficulty: interview

Starter code:

Solutions:
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))

possible = [[] for i in range(n)]

for i in range(n):
    for j in range(m):
        possible[i].append(a[i] & b[j])

import sys
for answer in range(2 ** 9):
    answer_flag = 1
    for i in range(n):
        flag = 0
        for x in possible[i]:
            if answer | x == answer:
                flag = 1
                break
        if flag == 0:
            answer_flag = 0
            break
    if answer_flag:
        print(answer)
        return


mem = [[-1 for j in range(201)] for i in range(1<<10)]
def dp(i,j,n,m,a,b):
    if(j==n):
        return 0
    if(mem[i][j]!=-1):
        return mem[i][j]
    ans = 1<<10
    for k in range(m):
        ans = min(ans,(i|(a[j]&b[k]))|dp(i|(a[j]&b[k]),j+1,n,m,a,b))
    mem[i][j] = ans
    return ans
n,m = map(int,input().split())
a = [*map(int,input().split())]
ans = 0
b = [*map(int,input().split())]
print(dp(0,0,n,m,a,b))

import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

# available on Google, not available on Codeforces
# import numpy as np
# import scipy


def solve(arr, brr):  # fix inputs here
    console("----- solving ------")

    for candidate in range(512):
        for a in arr:
            for b in brr:
                if a&b | candidate == candidate:
                    break
            else:
                break
        else:
            return candidate


def console(*args):  # the judge will not read these print statement
    print('\033[36m', *args, '\033[0m', file=sys.stderr)
    return

# fast read all
# sys.stdin.readlines()

# for case_num in range(int(input())):
    # read line as a string
    # strr = input()

    # read line as an integer
    # k = int(input())
    
    # read one line and parse each word as a string
    # lst = input().split()

    # read one line and parse each word as an integer
_ = list(map(int,input().split()))
arr = list(map(int,input().split()))
brr = list(map(int,input().split()))

    # read matrix and parse as integers (after reading read nrows)
    # lst = list(map(int,input().split()))
    # nrows = lst[0]  # index containing information, please change
    # grid = []
    # for _ in range(nrows):
    #     grid.append(list(map(int,input().split())))

res = solve(arr, brr)  # please change
    
    # Google - case number required
    # print("Case #{}: {}".format(case_num+1, res))

    # Codeforces - no case number required
print(res)


#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

for target in range(2**9):
    mask = ~target
    all_ok = True
    for ai in a:
        ok = False
        for bi in b:
            if not (ai & bi) & mask:
                ok = True
                break
        if not ok:
            all_ok = False
            break
    if all_ok:
        print(target)
        return

n, m = list(map(int, input().split()))
ln = list(map(int, input().split()))
lm = list(map(int, input().split()))

for ans in range(512):
    poss = True
    for i in ln:
        curr = False
        for j in lm:
            if (i & j) | ans == ans:
                curr = True
        if curr == False:
            poss = False

    if poss == True:
        print(ans)
        break


c = 0
n,m = map(int,input().split())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
al.sort(key = lambda a: min([a&b for b in bl]))
al.reverse()
for a in al:
    minc = pow(10,12)
    for b in bl:
        minc = min(minc, c | (a&b))
    c = int(minc)
print(c)

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

M = [[a[i]&b[j] for j in range(m)] for i in range(n)]
res = 0
M = sorted(M, key=lambda x: min(x), reverse = True)
for x in M:
	res = min([e|res for e in x])
print(res)

from collections import defaultdict as dd
import math
import sys
input=sys.stdin.readline
def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))


n,m = mi()

a_s = lm()

b_s = lm()

elim = []




for power in reversed(list(range(0,10))):
	bad = False
	for a in a_s:
		found = False
		for b in b_s:
			b_bad = False
			for pre_pow in elim:
				if a & (1<<pre_pow) and b & (1<<pre_pow):
					b_bad = True
			if a & (1<<power) and b & (1<<power):
				#print(a, 1<<power)
				#print(b, 1<<power)
				b_bad = True
			if b_bad == False:
				found = True
		if not found:
			bad = True
			break
	#print(bad)
	if not bad:
		elim.append(power)
ans = 0
for i in range(0,10):
	if i not in elim:
		ans+=2**i


print(ans)


n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c=0
for i in range(0,513):
    c=1
    for j in a:
        u = 0
        for k in b:
            if(i|(j&k)==i):
                u = 1
                break
        if(u==0):
            c=0
            break
    if(c==1):
        print(i)
        break

a,b=map(int,input().split())
r1=list(map(int,input().split()))
r2=list(map(int,input().split()))
for target in range(2**9):
	ans=0
	g = True
	for i in range(a):
		f = False
		for j in range(b):
			t = r1[i] & r2[j]
			if t & target == t:
				f = True
				break
		if not f:
			g = False
			break
	if g:
		print(target)
		return