import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") k,n = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def sub(a,b): return max([min(a[i], b[i]) for i in range(k)]) l = a[:] for i in range(100*k+1): l.append(sub(l[-k:], b)) if n