# from pickle import NEWFALSE
import sys
import heapq #最小堆,最大堆
n,m = map(int,input().split())
line1 = list(map(int,input().split()))
max1 = max(line1)
line2 = map(int,input().split())
heapq.heapify(line1) #直接将line1转为小顶堆,时间复杂度O(n)
for x in line2:
min1 = heapq.heappop(line1)
new = min1 + x
heapq.heappush(line1,new)
if new > max1:
max1 = new #更新最大值
print(new)
else:
print(max1)

京公网安备 11010502036488号