Problem:
Problem A: Equal Total Scores Taro and Hanako have numbers of cards in their hands.  
Each of the cards has a score on it.
Taro and Hanako wish to make the total scores of their cards equal
by exchanging one card in one's hand with one card in the other's hand.
Which of the cards should be exchanged with which? Note that they have to exchange their
cards even if they already have cards of the same total score. Input The input consists of a number of datasets. 
Each dataset is formatted as follows.   n  m  s 1   s 2  ...  s n   s n +1   s n +2  ...  s n + m     The first line of a dataset contains two numbers n and m delimited by a space, where n is the number of cards that Taro has
and m is the number of cards that Hanako has. 
The subsequent n + m lines 
list the score for each of the cards,
one score per line. The first n scores
(from s 1 up to s n )
are the scores of Taro's cards 
and the remaining m scores 
(from s n +1 up to s n + m )
are Hanako's. The numbers n and m are positive integers no greater than 100.  Each score
is a non-negative integer no greater than 100. The end of the input is indicated by a line containing two zeros delimited
by a single space. Output For each dataset, output a single line containing two numbers delimited
by a single space, where the first number is the score of the card Taro
gives to Hanako and the second number is the score of the card Hanako gives
to Taro. 
If there is more than one way to exchange a pair of cards
that makes the total scores equal, 
output a pair of scores whose sum is the smallest. In case no exchange can make the total scores equal, output a
single line containing solely -1.
The output must not contain any superfluous characters
that do not conform to the format. Sample Input 2 2
1
5
3
7
6 5
3
9
5
2
3
3
12
2
7
3
5
4 5
10
0
3
8
1
9
6
0
6
7 4
1
1
2
1
2
1
4
2
3
4
3
2 3
1
1
2
2
2
0 0 Output for the Sample Input 1 3
3 5
-1
2 2
-1

Solution (Python):
while True:
    m,n=map(int,input().split())
    if m==0 and n==0:
        break
    A=[]
    B=[]
    S=0
    T=0
    V=0
    for i in range(m):
        a=int(input())
        A.append(a)
        S=S+a
    for i in range(n):
        b=int(input())
        B.append(b)
        T=T+b
    for j in range(m):
        for k in range(n):
            J=A[j]
            K=B[k]
            X=S-J+K
            Y=T-K+J
            if X==Y and V==0:
                print(J,K)
                V=1
    if V==0:
        print('-1')

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==0:
        break
    a=[int(input()) for _ in range(n)]
    b=[int(input()) for _ in range(m)]
    a.sort()
    b.sort()
    sumA=sum(a)
    sumB=sum(b)
    def search():
        for i in a:
            for j in b:
                if (i-j)*2==sumA-sumB:
                    print(i,j)
                    return
        print(-1)
    search()

Solution (Python):
while True:
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break

    taro = [int(input()) for i in range(n)]
    hanako = [int(input()) for i in range(m)]

    taro.sort()
    hanako.sort()

    diff = sum(taro) - sum(hanako)

    if diff % 2 != 0:
        print(-1)
        continue

    diff /= 2

    ti = 0
    hi = 0

    flag = False
    while ti < n and hi < m:
        if taro[ti] - hanako[hi] == diff:
            print(taro[ti], hanako[hi])
            flag = True
            break
        else:
            if taro[ti] - hanako[hi] < diff:
                ti += 1
            else:
                hi += 1

    if not flag:
        print(-1)

Solution (Python):






while True:
    n, m = map(int, input().split())
    
    if n == 0 and m == 0:
        break
    
    else:
        taro = []
        hana = []
        
        for i in range(n):
            taro.append(int(input()))
        for i in range(m):
            hana.append(int(input()))
        
        taro.sort
        hana.sort
            
        sum_t = sum(taro)
        sum_h = sum(hana)

        sa = sum_t - sum_h 
        
        f = 0
        
        for i in range(n):
            if f == 1:
                break
            for j in range(m):
                if taro[i] == hana[j] + sa/2:
                    print(taro[i],hana[j])
                    f = 1
                    break
        
        if f == 0:
            print(-1)

Solution (Python):
while True:
   n,m = map(int, input().split())
   if n == 0 and m == 0:
      break
   T = []
   H = []
   for i in range(n):
      t = int(input())
      T.append(t)
   for j in range(m):
      h = int(input())
      H.append(h)
      
   T.sort()
   H.sort()
   min = []
   
   if (sum(T) - sum(H))%2!=0 or (sum(H) - sum(T))%2!=0:
      pass
   elif sum(T) > sum(H):
      s = (sum(T) - sum(H))//2
      for p in range(n):
         for q in range(m):
            if min == []:
               if T[p] - s == H[q]:
                  min = [T[p], H[q]]
            else:
               break
   elif sum(T) < sum(H):
      s = (sum(H) - sum(T))//2
      for p in range(n):
         for q in range(m):
            if min == []:
               if T[p] + s == H[q]:
                  min = [T[p], H[q]]
            else:
               break
   else:
      for p in range(n):
         for q in range(m):
            if T[p] == H[q]:
               if sum(min) > T[p]+H[q] or min == []:
                  min = [T[p], H[q]]

   if min == []:
      print('-1')
   else:
      print(*min)

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n==0 and m==0:
        break
    lt=[]
    lh= []
    for i in range(n):
        sn=int(input())
        lt.append(sn)
    for j in range(m):
        sm=int(input())
        lh.append(sm)
    s = (sum(lt)+sum(lh))/2
    st= abs(s-sum(lt))
    lt.sort()  
    lh.sort()
    if sum(lt) < sum(lh):
        ans = -1
        for i in lt:
            if ans==-1:
                for j in lh:
                    if i + st == j:
                        print(i,j)
                        ans = 1
                        break
        if ans==-1:
            print(ans)
    else:
        ans = -1
        for j in lh:
            if ans==-1:
                for i in lt:
                    if j + st == i:
                        print(i,j)
                        ans = 1
                        break 
        if ans==-1:
            print(ans)

Solution (Python):


while True:
    taro_cards,hanako_cards = map(int,input().split())
    if taro_cards==0 and hanako_cards==0:
        break
    taros_card = [int(input()) for _ in range(taro_cards)]
    hanakos_card = [int(input()) for _ in range(hanako_cards)]

    diff = sum(taros_card) - sum(hanakos_card)
    taros_card.sort()
    hanakos_card.sort()

    answer_i = 0
    answer_j = 0
    answer_total = 99999
    
    for i in range(taro_cards):
        for j in range(hanako_cards):
            if sum(taros_card) - 2*taros_card[i] == sum(hanakos_card) - 2*hanakos_card[j]  and taros_card[i] + hanakos_card[j] <= answer_total:
                answer_i = taros_card[i] 
                answer_j = hanakos_card[j]
                answer_total = taros_card[i] + hanakos_card[j]
    
    if answer_total == 99999:
        print(-1)
    else:
        print(str(answer_i)  + " "+str(answer_j) )

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    st=[int(input()) for t in range(n)]
    sh=[int(input()) for h in range(m)]
    st.sort()
    sh.sort()
    x=0
    y=0
    for i in range(len(st)):
        if y==1:
            break
        for j in range(len(sh)):
            if sum(st)-st[i]+sh[j]==sum(sh)+st[i]-sh[j]:
                print(st[i],sh[j])
                y=1
                break
            else:
                x+=1
    if x==len(st)*len(sh):
        print('-1')

Solution (Python):
def f():
    for i in t:
        for j in h:
            if (i-j)*2==sumt-sumh:
                print(i,j)
                return
    print(-1)
            

while True:
    n,m=map(int,input().split())
    if n==0:
        break
    t=[int(input()) for i in range(n)]
    h=[int(input()) for j in range(m)]
    t.sort()
    h.sort()
    sumt=sum(t)
    sumh=sum(h)
    f()

Solution (Python):

while True:
    n,m = map(int,input().split())
    if n==m==0: break
    
    taro = [int(input()) for i in range(n)]
    hanako = [int(input()) for i in range(m)]

    ans1 = []; ans2 = []
        
    for i in sorted(taro):
        for j in sorted(hanako):
            if sum(taro)-i+j == sum(hanako)-j+i:
                ans1.append(i); ans2.append(j)
    
    if len(ans1)==len(ans2)==0: print(-1)
    else: print(ans1[0],ans2[0])

Solution (Python):



while True:
   n, m = map(int, input().split())
   if n + m == 0: 
      break
   
   sums = 0 
   TARO = []
   for i in range(n):
      taro = int(input())
      TARO.append(taro)
      sums += taro

   sumh = 0 
   HANAKO = []
   for i in range(m):
      hanako = int(input())
      HANAKO.append(hanako)
      sumh += hanako

   
   
   
   mid = (sums + sumh) / 2  
   dif = abs(sums - mid)
   
   
   TARO.sort()
   HANAKO.sort()
   
   c = 0
   for i in range(n):
      for j in range(m):
         if (sums + sumh) % 2 == 1:
            c += 0
         else:
            if sums == sumh:
               if TARO[i] == HANAKO[j]:
                  print(TARO[i], HANAKO[j])
                  c += 1
                  break
            if TARO[i] - HANAKO[j] == dif:
               if sums > sumh:
                  print(TARO[i], HANAKO[j])
                  c += 1
                  break
            if HANAKO[j] - TARO[i] == dif:
               if sumh > sums:
                  print(TARO[i], HANAKO[j])
                  c += 1
                  break
      else:
         continue
      break

   if c == 0:
      print(-1)

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    a=[int(input()) for i in range(n)]
    b=[int(input()) for i in range(m)]
    ans=[-1]
    va=100000
    for i in range(n):
        for j in range(m):
            if sum(a)-a[i]+b[j]==sum(b)-b[j]+a[i]:
                if (a[i]+b[j])<va:
                    va=a[i]+b[j]
                    ans=a[i],b[j]
    print(*ans)

Solution (Python):
import sys
import math
import itertools
input = sys.stdin.readline


while True:
    n, m = input().rstrip().split()
    n, m = int(n), int(m)
    if n + m == 0:
        sys.exit()
    
    taro = []
    hanako = []
    for _ in range(n):
        taro.append(int(input().rstrip()))
    for _ in range(m):
        hanako.append(int(input().rstrip()))

    card_diff = sum(taro) - sum(hanako)
    if card_diff % 2 == 1:
        print("-1")
        continue
    else:
        card_diff = card_diff // 2

    found_flag = False
    for piv_taro, piv_hanako in itertools.product(range(0, n), range(0, m)):
        if (taro[piv_taro] - hanako[piv_hanako]) == card_diff:
            found_flag = True
            break
    if found_flag == True:
        print("{} {}".format(taro[piv_taro], hanako[piv_hanako]))
    else:
        print("-1")

Solution (Python):
while True:
    m,n = map(int,input().split())
    
    if  m== 0 and n == 0:
        break
    
    ta=[]
    ha=[]
    for i in range(m):
        ta.append(int(input()))
        
    for i in range(n):
        ha.append(int(input()))
    
    ta=sorted(ta)
    ha=sorted(ha)
    ans1=[]
    ans2=[]
    for i in sorted(ta):
        for j in sorted(ha):
            if sum(ta) - i + j == sum(ha) - j + i:
                ans1.append(i)
                ans2.append(j)
    
    if len(ans1)==0 and len(ans2)==0:
        print(-1)
    
    else:
        print(ans1[0],ans2[0])

Solution (Python):
while True:
    data = input().split()
    n,m = int(data[0]),int(data[1])
    if n == 0 and m == 0: break

    tarou_cards = []
    hanako_cards = []
    cards_size = n + m

    total = 0
    t_total = 0
    h_total = 0

    for i in range(0,cards_size):
        point = int(input())
        total += point
        if n >= i+1:
            tarou_cards.append(point)
            t_total += point
        else:
            hanako_cards.append(point)
            h_total += point
    tarou_cards.sort()
    hanako_cards.sort()

    if total%2 != 0:
        print("-1")
        continue
    
    exchangeFlg = False
    target = t_total - total/2
    for t_card in tarou_cards:
        for h_card in hanako_cards:
            diff = t_card - h_card
            if diff == target:
                print("{} {}".format(t_card,h_card))
                exchangeFlg = True
                break
        if exchangeFlg:
            break
    if exchangeFlg != True:
        print("-1")

Solution (Python):
while True:
    try:
        n, m = map(int, input().split())
        
        if n==0 and m==0:
            break
    except:
        break
    
    Taro = []
    for i in range(n):
        s = int(input())
        Taro.append(s)
    Hana = []
    for i in range(m):
        s = int(input())
        Hana.append(s)
    
    koukan = []
    kknsum = []
    for i in range(n):
        taro = Taro
        tarou = taro[i]
        taro.pop(i)
        tsum = sum(taro)
        taro.insert(i,tarou)
        for j in range(m):
            hana = Hana
            hanak = hana[j]
            hana.pop(j)
            hsum = sum(hana)
            hana.insert(j,hanak)
            sumTa = tsum + hanak
            sumHa = hsum + tarou
            if sumTa==sumHa:
                koukan.append([tarou, hanak])
                kknsum.append(tarou+hanak)
    
    if koukan==[]:
        print('-1')
    
    else:
        kknmin = min(kknsum)
        index = kknsum.index(kknmin)
        kk = koukan[index]
        print(kk[0], kk[1])

Solution (Python):
while True :
    n, m = map(int, input().split())
    
    if n == 0 :
        break
    
    else :
        T = []
        H = []
        
        for i in range(n) :
            T.append(int(input()))
            
        for i in range(m) :
            H.append(int(input()))
        
        Ts = sorted(T)
        Hs = sorted(H)
        
        sumT = sum(Ts)
        sumH = sum(Hs)
        
        d = (sumT - sumH) / 2
        D = abs(d)
        
        f = 0
        
        
        if d < 0 :
            for i in range(len(Ts)) :
                if (Ts[i] + D) in Hs :
                    print(Ts[i], int(Ts[i] + D))
                    f = 1
                    break
        else :
            for i in range(len(Ts)) :
                if (Ts[i] - D) in Hs :
                    print(Ts[i], int(Ts[i] - D))
                    f = 1
                    break
        
        if f != 1 :
            print(-1)

Solution (Python):
while True:
    s=[]
    t=[]
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    else:
        for i in range(n):
            x=int(input())
            s.append(x)
        for i in range(m):
            y=int(input())
            t.append(y)
        s.sort()
        t.sort()
        def search():
            for a in s:
                 for b in t:
                    if (a-b)*2==sum(s)-sum(t):
                        print(a,b)
                        return
            print(-1)
        search()

Solution (Python):
while True :
    n, m = map(int, input().split())
    if n == 0 and m == 0 :
        break
    
    list_n = list(int(input()) for i in range(n))
    list_m = list(int(input()) for i in range(m))
    list_n.sort
    list_m.sort
    sum_n = sum(list_n)
    sum_m = sum(list_m)
    if sum_n >= sum_m :
        sa = sum_n - sum_m
        result = -1
        for i in range(n) :
            if result == 1 :
                break
            for j in range(m):
                if list_n[i] == list_m[j] + sa / 2 :
                    print(list_n[i], list_m[j])
                    result = 1
                    break
        if result == -1 :
            print(-1)
            
            
    elif sum_n <= sum_m :
        sa = sum_m - sum_n
        result = -1
        for i in range(n) :
            if result == 1 :
                break
            for j in range(m):
                if list_m[j] == list_n[i] + sa / 2:
                    print(list_n[i], list_m[j])
                    result = 1
                    break
        if result == -1 :
            print(-1)

Solution (Python):
def get_two_int():
    two_int = input().split()
    for i in range(2):
        two_int[i] = int(two_int[i])
    return two_int

def make_sorted_num_list(num):
    num_list = [None] * num
    for i in range(num):
        num_list[i] = int(input())
    sorted_num_list = sorted(num_list)
    return sorted_num_list

def shuffle(first_list, second_list):
    flag = False
    dif_value = sum(first_list) - sum(second_list)
    if abs(dif_value) % 2 != 0:
        return flag, -1
    for i in first_list:
        for j in second_list:
            if i - j == (dif_value // 2):
                flag = True
                return flag, i, j
    return flag, -1


if __name__ == "__main__":
    while True:
        taro_num, hanako_num = get_two_int()
        if taro_num == hanako_num == 0:
            break
        taro_list = make_sorted_num_list(taro_num)
        hanako_list = make_sorted_num_list(hanako_num)
        ans = shuffle(taro_list, hanako_list)
        if ans[0] == False:
            print(ans[1])
        else:
            print(ans[1], ans[2])

Solution (Python):
while 1:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    taro = [int(input()) for i in range(n)]
    hanako = [int(input()) for i in range(m)]
    ans = []
    for i in range(n):
        for j in range(m):
            taro[i],hanako[j] = hanako[j],taro[i]
            if sum(taro) == sum(hanako):
                ans.append([hanako[j],taro[i]])
            taro[i],hanako[j] = hanako[j],taro[i]
    Min = 9999999999
    for i,j in ans:
        if Min > (i+j):
            Min = (i+j)
            ans_taro = i
            ans_hanako = j
    if len(ans) != 0:
        print(ans_taro,ans_hanako)
    else:
        print(-1)

Solution (Python):
while (True):
    n,m=map(int,input().split())
    if n==m==0:
        exit()
    lst_a=[int(input()) for _ in range(n)]
    lst_b=[int(input()) for _ in range(m)]
    a_sum=sum(lst_a)
    b_sum=sum(lst_b)
    min_lst=[]
    
    for a in lst_a:
        keisan_a=a_sum
        keisan_b=b_sum
        for b in lst_b:
            if keisan_a -a+b == keisan_b +a-b:
                min_lst.append((a+b,a,b))
    
    
    if min_lst:
        ans=sorted(min_lst)    
        print(ans[0][1],ans[0][2])
                
    else:print(-1)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(0, 1), (1, 0), (0, -1), (-1, 0)]

def main():
    while 1:
        n,m=MI()
        if n==0:break
        aa=[II() for _ in range(n)]
        sa=sum(aa)
        sb=0
        bb=set()
        for _ in range(m):
            b=II()
            sb+=b
            bb.add(b)
        d=sa-sb
        if d%2:
            print(-1)
            continue
        d//=2
        for a in aa:
            if a-d in bb:
                print(a,a-d)
                break
        else:
            print(-1)

main()

Solution (Python):
while 1:
    n,m = map(int,input().split())
    if n==0: break
    t = sorted([int(input()) for _ in range(n)])
    h = sorted([int(input()) for _ in range(m)])
    d = sum(t) - sum(h)
    if d%2 != 0: print(-1);continue
    for i in range(n):
        if t[i] - d//2 in h:
            print(t[i], t[i] - d//2)
            break
    else:
        print(-1)

Solution (Python):
while 1:
    n, m = [int(i) for i in input().split()]

    if n == 0 and m == 0:
        break
    
    taro = []
    hanako = []

    for i in range(n):
        s = int(input())
        taro.append(s)
    for i in range(m):
        s = int(input())
        hanako.append(s)

    sum_taro = sum(taro)
    sum_hanako = sum(hanako)

    ex_min = max(taro) + max(hanako)
    min_taro = 0
    min_hanako = 0

    for i in range(n):
        for j in range(m):
            ex_sum_taro = sum_taro - taro[i] + hanako[j]
            ex_sum_hanako = sum_hanako + taro[i] - hanako[j]
            if ex_sum_taro == ex_sum_hanako:
                if (min_taro == 0 and min_hanako == 0) or \
                   (min_taro + min_hanako < ex_min):
                    min_taro = taro[i]
                    min_hanako = hanako[j]
                    ex_min = min_taro + min_hanako

    if min_taro == 0 and min_hanako == 0:
        print(-1)
    else:
        print(min_taro, min_hanako)

Solution (Python):
while True:
    n, m = [int(x) for x in input().split()]
    if n == 0 and m == 0:
        break

    L = []
    M = []
    for _ in range(n):
        L.append(int(input()))

    for _ in range(m):
        M.append(int(input()))

    diff = sum(M) - sum(L)
    if diff %2:
        print(-1)
        continue
    else:
        diff = diff//2

    f = 0
    setm = set(M)
    for i in sorted(set(L)):
        j = i + diff
        if j in setm:
            f += 1
            break

    if f > 0:
        print(i,j)
    else:
        print(-1)

Solution (Python):
ans_list = []

while True:
    n,m = map(int,input().split())
    if (n,m) == (0,0):
        break
    S = [int(input()) for _ in range(n)]
    T = [int(input()) for _ in range(m)]
    ss = sum(S)
    tt = sum(T)
    ans = (101,101)
    for s in S:
        for t in T:
            if ss - s + t == tt - t + s and s + t < sum(ans):
                ans = (s,t)
    if ans == (101,101):
        ans = -1
    else:
        ans = "{} {}".format(ans[0],ans[1])
    ans_list.append(ans)

for ans in ans_list:
    print(ans)

Solution (Python):

"""
def solve(n,p):
    a = [0]*n
    for _ in range(1000000):
        for i in range(n):
            if p:
                p -= 1
                a[i] += 1
                if p == 0:
                    if sum(a)-a[i] == 0:
                        return i
            else:
                p += a[i]
                a[i] = 0

while 1:
    n,p = [int(x) for x in input().split()]
    if n == 0:
        break
    print(solve(n,p))
"""


def solve(n,m):
    s = [int(input()) for i in range(n)]
    t = [int(input()) for i in range(m)]
    s_s = sum(s)
    s_t = sum(t)
    ans = (-1,float("inf"))
    for i in range(n):
        for j in range(m):
            a = s_t-s_s-2*t[j]+2*s[i]
            if a == 0:
                if s[i]+t[j] < sum(ans):
                    ans = (s[i],t[j])
    if ans[0] < 0:
        print(-1)
    else:
        print(*ans)
while 1:
    n,m = [int(x) for x in input().split()]
    if n == 0:
        break
    solve(n,m)

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n == 0:
        exit()
    t = []
    h = []
    ans = []
    for i in range(n):
        t.append(int(input()))
    for i in range(m):
        h.append(int(input()))
    for i in range(n):
        for j in range(m):
            if (sum(t) - t[i] + h[j]) == (sum(h) - h[j] + t[i]):
                ans.append([t[i] + h[j], t[i], h[j]])
    ans = sorted(ans)
    if len(ans) != 0:
        print(str(ans[0][1]) + " " + str(ans[0][2]))
    else:
        print(-1)

Solution (Python):
from itertools import product
while True:
  N, M = map(int, input().split())
  if N==M==0:
    break
  A = [int(input()) for _ in range(N)]
  B = [int(input()) for _ in range(M)]
  sumA = sum(A)
  sumB = sum(B)
  ans = [-1]
  wa = float("inf")
  for (ia, a), (ib, b) in product(enumerate(A), enumerate(B)):
    if sumA - a + b == sumB - b + a:
      if wa > a + b:
        wa = a + b
        ans = a, b
  print(*ans)

Solution (Python):
def main(n, m):
    a = [int(input()) for i in range(n)]
    b = [int(input()) for i in range(m)]
    suma = sum(a)
    sumb = sum(b)
    ans = []
    for ai in a:
        for bi in b:
            if suma - ai + bi == sumb - bi + ai:
                ans.append((ai, bi))
    if ans == []:
        print(-1)
        return
    ans.sort(key=lambda x: x[0] + x[1])
    print(ans[0][0],ans[0][1])


while 1:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    main(n, m)

Solution (Python):
while True:
  n,m=map(int,input().split())
  if n==0 and m==0:
    break
  tarou=[]
  hanako=[]
  kumit=[]
  kumih=[]
  wa=[]
  for i in range(n):
    tarou.append(int(input()))
  for i in range(m):
    hanako.append(int(input()))
  for i in range(n):
    a=tarou[i]
    for j in range(m):
      b=hanako[j]
      x=sum(tarou)-a+b
      y=sum(hanako)-b+a
      if x==y:
        kumit.append(tarou[i])
        kumih.append(hanako[j])
        wa.append(tarou[i]+hanako[j])
  if wa!=[]:
    for i in range(len(wa)):
      if wa[i]==min(wa):
        print(kumit[i],kumih[i])
        break
  else:
    print(-1)

Solution (Python):



while 1:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    taro = [int(input()) for _ in range(n)]
    hanako = [int(input()) for _ in range(m)]
    change = []
    for i in range(n):
        for j in range(m):
            taro[i],hanako[j] = hanako[j],taro[i]
            if sum(taro) == sum(hanako):
                change.append([hanako[j],taro[i],taro[i]+hanako[j]])
            taro[i],hanako[j] = hanako[j],taro[i]
    
    change = sorted(change, key = lambda x:x[2])
    if len(change) == 0:
        print(-1)
    else:
        print(change[0][0],change[0][1])

Solution (Python):
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = [0] * n
    b = [0] * m
    sum_a = 0
    sum_b = 0
    for i in range(n):
        a[i] = int(input())
        sum_a += a[i]
    for i in range(m):
        b[i] = int(input())
        sum_b += b[i]
    a = sorted(a)
    b = sorted(b)
    d = sum_a - sum_b
    if d % 2 != 0:
        print(-1)
    else:
        d /= 2
        ok = False
        for i in range(n):
            for j in range(m):
                if a[i] - b[j] == d:
                    print(a[i], b[j])
                    ok = True
                    break
            if ok:
                break
        if not ok:
            print(-1)

Solution (Python):
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    ans = False
    taro = sorted([int(input()) for _ in range(n)])
    hana = [int(input()) for _ in range(m)]
    diff = sum(taro) - sum(hana)
    hana = set(hana)
    for k in taro:
        if k - diff / 2 in hana:
            print(k, k - diff // 2)
            ans = True
            break
    if ans is False:
        print(-1)

Solution (Python):
def fun(n, m):
        n_total = 0
        N = []
        for _ in range(n):
                s = int(input())
                N.append(s)
                n_total += s
        m_total = 0
        M = []
        for _ in range(m):
                s = int(input())
                M.append(s)
                m_total += s
        flag = False
        for i in N:
                for j in M:
                        if n_total -i+j==m_total+i-j:
                                print(i,j)
                                flag = True
                                break
                if flag:
                        break
        if not flag:
                print(-1)
n, m = map(int, input().split())
while n != 0:
        fun(n, m)
        n, m = map(int, input().split())

Solution (Python):
while True:
  n, m = list(map(int, input().split()))
  if n==0:
    break

  a = [int(input()) for i in range(n)]
  b = [int(input()) for i in range(m)]
  sa = sum(a)
  sb = sum(b)
  a.sort()
  b.sort()

  ta, tb = 1e9, 1e9
  for i in range(n):
    for j in range(m):
      if (a[i]-b[j])*2==sa-sb:
        if ta+tb>a[i]+b[j]:
          ta, tb = a[i], b[j]

  if ta==1e9:
    print(-1)
  else:
    print(ta, tb)

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==0:
        break
    l1=[int(input()) for _ in range(n)]
    l2=[int(input()) for z in range(m)]
    sum1=sum(l1)
    sum2=sum(l2)
    l1.sort()
    l2.sort()
    a1=0
    a2=0
    while True:
        if a1+1>n or a2+1>m:
            print("-1")
            break
        else:
            if sum1-l1[a1]+l2[a2]==sum2+l1[a1]-l2[a2]:
                print("{} {}".format(l1[a1],l2[a2]))
                break
            elif sum1-l1[a1]+l2[a2]>sum2+l1[a1]-l2[a2]:
                a1+=1
            else:
                a2+=1

Solution (Python):


ans = []

while True:
    flag = False
    n, m = map(int, input().split())
    if n == 0 and m == 0:
        break
    s = [int(input()) for i in range(n)]
    t = [int(input()) for i in range(m)]

    sum_s = sum(s)
    sum_t = sum(t)

    for i in range(n):
        for j in range(m):
            
            if (sum_s - s[i] + t[j]) == (sum_t - t[j] + s[i]):
                flag = True
                ans.append([s[i], t[j]])
                break
        if flag:
            break

    if not flag:
        ans.append([-1, -1])

for i in ans:
    if -1 in i:
        print(-1)
    else:
        print("{} {}".format(i[0], i[1]))

Solution (Python):
CARDMAX = 100
POINTMAX = 100
    
def main():
    head = []
    c_taro = []
    c_hana = []

    while True:
        
        head.clear()
        c_taro.clear()
        c_hana.clear()

        
        head = input()
        head = head.split(" ")

        
        if head == ['0', '0']:
            return 0

        for j in range(int(head[0])):
            c_taro.append(int(input()))

        for j in range(int(head[1])):
            c_hana.append(int(input()))

        sum_taro = showsum(c_taro)
        sum_hana = showsum(c_hana)
        avee = showave(sum_taro, sum_hana)
        toave = avee - sum_taro

        print(showchcard(c_taro, c_hana, toave))
"""
        print("headdata::")
        print(head)
        print("c_taro::")
        print(c_taro)
        print("c_hana::")
        print(c_hana)
        print("sum_taro::")
        print(sum_taro)
        print("sum_hana::")
        print(sum_hana)
        print("average::")
        print(avee)
        print("")
"""

def showsum(array):
    summ = 0
    for item in array:
        summ += item
    return summ

def showave(a, b):
    return (a + b) / 2

def showchcard(tarray, harray, toave):
    wa = CARDMAX * 2 + 1
    for tnum in tarray:
        for hnum in harray:
            if hnum - tnum == toave:
                if wa >= (hnum + tnum):
                    tans = tnum
                    hans = hnum
                    wa = tans + hans

    if wa != CARDMAX * 2 + 1:
        result = str(tans) + " " + str(hans)
        return result
    else:
        return -1

main()