import sys from collections import deque def main(): K, N = map(int, sys.stdin.readline().split()) A = list(map(int, sys.stdin.readline().split())) B = list(map(int, sys.stdin.readline().split())) if N < K: print(A[N]) return window = deque(A) for _ in range(K, N+1): next_val = max(min(window[j], B[j]) for j in range(K)) window.popleft() window.append(next_val) # Check if all elements in the window are the same all_same = True first = window[0] for val in window: if val != first: all_same = False break if all_same: print(first) return print(window[-1]) if __name__ == "__main__": main()