n=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]

s=sum(a)

min=abs(sum(b)-s)
idx=[0,n[1]]
for i in range(0,n[1]):
    for j in range(i+1,n[1]+1):
        if abs(sum(b[i:j])-s)<min:
            min=abs(sum(b[i:j])-s)
            idx[0]=i
            idx[1]=j
print(' '.join(str(i) for i in b[idx[0]:idx[1]]))