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:
    n,m=map(int,input().split())
    if n==0:break
    a=[int(input())for _ in range(n)]
    b=[int(input())for _ in range(m)]
    sa=sum(a)
    sb=sum(b)
    f=0
    for i in a:
        for j in b:
            if sa-i+j==sb-j+i:
                print(i,j)
                f=1
                break
        if f:
            break
    else:
        print(-1)

Solution (Python):



INF = 0x7fffff
while True:
	n, m = 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) - sum(b)
	ss = INF
	for i in range(n):
		for j in range(m):
			if ((a[i]-b[j])<<1) == sa:
				if a[i]+b[j] < ss:
					aa, bb = a[i], b[j]
					ss = aa + bb;
	if ss == INF: print(-1)
	else: print(aa, bb)

Solution (Python):
while True:
    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)]
    trade_n = []
    trade_m = []
    for t in taro:
        for h in hanako:
            if (sum(taro) - t + h) == (sum(hanako) - h + t):
                trade_n.append(t)
                trade_m.append(h)
    if len(trade_n) >= 1:
        ans = [0, 100000]
        for i in range(len(trade_n)):
            ans[1] = min(trade_n[i] + trade_m[i], ans[1])
            if ans[1] == trade_n[i] + trade_m[i]:
                ans[0] = i
        print("{} {}".format(trade_n[ans[0]], trade_m[ans[0]]))
    elif len(trade_n) == 0:
        print(-1)

Solution (Python):
anslist = []
while True:
    ans = 0
    n, m = map(int, 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)
    ans = -1
    for i in range(n):
        for j in range(m):
            if sum(taro) - taro[i] + hanako[j] == sum(hanako) - hanako[j] + taro[i]:
                ans = [taro[i], hanako[j]]
                break
        if ans != -1:
            break

    anslist.append(ans)

for i in anslist:
    if i == -1:
        print(-1)
    else:
        print(i[0], i[1])

Solution (Python):
def answer(n, m, taro, hanako):
    for t in sorted(taro):
        for h in sorted(hanako):
            if sum(taro) - t + h == sum(hanako) - h + t:
                return f'{t} {h}'
    return -1


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

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

while True:
    n,m = inpl()
    if n == 0:
        break
    else:
        aa = [inp() for _ in range(n)]
        bb = [inp() for _ in range(m)]
        Sa = sum(aa)
        Sb = sum(bb)
        for a in aa:
            for b in bb:
                if Sa-a+b == Sb+a-b:
                    print(a,b)
                    break
            else:
                continue
            break
        else:
            print(-1)

Solution (Python):
while True:
  n,m = map(int,input().split())
  if n + m == 0:
    break
  Taro = [int(input()) for _ in range(n)]
  Hana = [int(input()) for _ in range(m)]
  st = sum(Taro)
  sh = sum(Hana)
  for t in range(n):
    for h in range(m):
      if st - 2*Taro[t] == sh - 2*Hana[h]:
        print(Taro[t],Hana[h])
        st = 114514
        break
      if t==n-1 and h==m-1:
        print(-1)
    if st==114514:
      break

Solution (Python):
while True:
    (n, m) = [int(x) for x in input().split()]
    if n==0 and m==0:
        exit()
    a = []
    b = []
    for i in range(n):
        a.append(int(input()))
    for i in range(m):
        b.append(int(input()))
    a_sum = sum(a)
    b_sum = sum(b)
    target = a_sum - b_sum
    found = False
    for ai in a:
        for bi in b:
            if (ai-bi)*2 == target:
                print(ai, bi)
                found = True
            if found:
                break
        if found:
            break
    if found == False:
        print(-1)

Solution (Python):



import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n, m = map(int, raw_input().split())
            if n == 0 and m == 0:
                break
            sn = []
            for i in range(n):
                sn.append(input())
            sm = []
            for i in range(m):
                sm.append(input())
            diff = (sum(sn) - sum(sm)) * 1.0 / 2
            
            
            
            ans = []
            flg = False
            for i in sn:
                for j in sm:
                    if i - j == diff:
                       flg = True
                       ans.append((i, j))
            if flg == False:
                print -1
                continue
            min_points = min(i + j for i, j in ans)
            for i, j in ans:
                if i + j == min_points:
                    print ' '.join([str(i), str(j)])
                    break
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Solution (Python):

while 1:
    n, m = list(map(int, input().split()))
    if n == 0:break
    n_v = [int(input()) for i in range(n)]
    m_v = [int(input()) for i in range(m)]

    n_s = sum(n_v)
    m_s = sum(m_v)

    swap_min = 99999999

    x = n_s - m_s

    res = '-1'
    for nv in n_v:
        for mv in m_v:
            
            if x == 2 * (nv - mv) and swap_min > nv + mv:
                swap_min = nv + mv
                res = '%d %d' % (nv,mv)
    print(res)

Solution (Python):



while True:
    n,m = map(int,input().split())
    if n == 0 and m == 0:
        break
    taro = [int(input()) for i in range(0,n)]
    hanako = [int(input()) for i in range(0,m)]
    taro_hand = sum(taro)
    hanako_hand = sum(hanako)
    ans = -1
    for i in sorted(taro):
        for j in sorted(hanako):
            if ans != -1:
                break
            if taro_hand + (j - i) == hanako_hand + (i - j):
                ans = str(i) + ' ' + str(j)
    print(ans)

Solution (Python):
while 1:
	n, m = map(int, raw_input().split(" "))
	if (n,m) == (0,0):
		break
	tarou = [int(raw_input()) for i in range(n)]
	t_total = sum(tarou)
	hanako = [int(raw_input()) for i in range(m)]
	h_total = sum(hanako)
	pair = (101,101)
	for t in tarou :
		for h in hanako:
			if t_total - t + h == h_total - h + t:
				if t + h <= sum(pair):
					pair = (t,h)
	if pair == (101,101):
		print -1
	else :
		print pair[0], pair[1]

Solution (Python):



(n, m) = map(int, raw_input().split())
while n!=0 or m!=0:
    T = [int(raw_input()) for i in range(n)]
    H = [int(raw_input()) for i in range(m)]
    min = [1000, 1000]
    for i in range(n):
        for j in range(m):
            if(sum(T)-T[i]+H[j] == sum(H)+T[i]-H[j] and sum(min) > H[j] + T[i]):
                min = [T[i], H[j]];
    if min == [1000, 1000]:
        print -1
    else:
        print min[0], min[1]
    
    (n, m) = map(int, raw_input().split())

Solution (Python):

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

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

    sum_taro = sum(taro)
    sum_hana = sum(hanako)
    dif = sum_taro - sum_hana




    ans_t, ans_h = 101, 101 
    for t in taro:
        for h in hanako:
            if (sum_taro - t + h) == (sum_hana - h + t) \
                    and (t + h) < (ans_t + ans_h):
                        ans_t, ans_h = t, h
    if (ans_t + ans_h) == 202:
        print(-1)
    else:
        print(ans_t, ans_h)

Solution (Python):
def impossible(taro_cards, hanako_cards, average):
    if (sum(taro_cards) + sum(hanako_cards)) % 2 == 1:
        return True
    elif sum(taro_cards) + max(taro_cards) - min(hanako_cards) < average:
        return True
    elif sum(hanako_cards) + max(hanako_cards) - min(taro_cards) < average:
        return True
    else:
        return False


while True:
    n_taro, n_hanako = map(int, input().split())
    if n_taro == 0 and n_hanako == 0:
        break

    taro_cards = []
    hanako_cards = []
    change_pairs = []

    for _ in range(n_taro):
        taro_cards.append(int(input()))
    for _ in range(n_hanako):
        hanako_cards.append(int(input()))

    average = (sum(taro_cards) + sum(hanako_cards)) // 2

    if impossible(taro_cards, hanako_cards, average):
        print(-1)
    else:
        
        for i in range(len(taro_cards)):
            for j in range(len(hanako_cards)):
                if sum(taro_cards[:i]) + sum(taro_cards[i+1:]) + hanako_cards[j] == average:
                    change_pairs.append((taro_cards[i], hanako_cards[j]))
                    

        
        if change_pairs == []:
            print(-1)
        else:
            pairs_leastsum = change_pairs[0]
            for i in range(1, len(change_pairs)):
                if sum(change_pairs[i]) <= sum(pairs_leastsum):
                    pairs_leastsum = change_pairs[i]
            print(*pairs_leastsum)

Solution (Python):

while True:
	n, m = map(int, input().split())
	if (n, m) == (0, 0):
		break
	res = None
	taro = [int(input()) for i in range(n)]
	hana = [int(input()) for i in range(m)]
	taros = sum(taro)
	hanas = sum(hana)
	diff = (hanas-taros)

	for i in range(n):
		for j in range(m):
			if diff == ((hana[j] - taro[i])*2):
				if res == None or sum(res) > (taro[i] + hana[j]):
					res = (taro[i], hana[j])

	if res == None:
		print(-1)
	else:
		print(' '.join(map(str, res)))

Solution (Python):
while True:
	n,m = raw_input().split(" ")
	n = int(n)
	m = int(m)
	if n*m==0:
		break
	a_all = 0
	b_all = 0
	A = []
	B = []
	for i in xrange(0,n):
		x = input()
		x = int(x)
		A.append(x)
		a_all += x
	for j in xrange(0,m):
		y = input()
		y = int(y)
		B.append(y)
		b_all += y
	A.sort()
	B.sort()
	sa = abs(a_all - b_all)
	if sa%2==1:
		print -1
	else:
		sa = sa / 2
		if(a_all < b_all):
			sa = sa * -1
		flag = False
		for i in xrange(0,n):
			for j in xrange(0,m):
				if (A[i]-B[j])==sa:
					print A[i],
					print B[j]
					flag = True
					break
			if flag==True:
				break
		if flag==False:
			print -1

Solution (Python):
while True:
    n, m = map(int, raw_input().split())

    if n == 0:
        break

    taro = [int(raw_input()) for i in range(n)]
    taro_sum = sum(taro)
    hanako = [int(raw_input()) for j in range(m)]
    hanako_sum = sum(hanako)

    pair = (101, 101)

    for t in taro:
        for h in hanako:
            if taro_sum - t + h == hanako_sum - h + t:
                if h + t <= sum(pair):
                    pair = (t, h)

    if pair == (101, 101):
        print - 1
    else:
        print pair[0], pair[1]

Solution (Python):



import array
import heapq
import itertools


def solve(taro_cards, hanako_cards):
    sum_taro = sum(taro_cards)
    sum_hanako = sum(hanako_cards)
    candidates = []
    for t, h in itertools.product(taro_cards, hanako_cards):
        if sum_taro - t + h == sum_hanako - h + t:
            heapq.heappush(candidates, (t + h, [t, h]))
    if not candidates:
        return [-1]
    else:
        return candidates[0][1]


if __name__ == "__main__":
    while True:
        n, m = map(int, input().split())
        if n == 0 and m == 0:
            break
        else:
            taro_cards = array.array("B", (int(input()) for i in range(n)))
            hanako_cards = array.array("B", (int(input()) for i in range(m)))
            print(*solve(taro_cards, hanako_cards))

Solution (Python):
def solve1():
    N, M = [int(s) for s in input().split()]
    if N == M == 0:
        return False
    taro = [int(input()) for _ in range(N)]
    taro.sort()
    hana = [int(input()) for _ in range(M)]
    hana.sort()
    diff = sum(taro) - sum(hana)
    ans = compare(diff, taro, hana);
    if ans is None:
        print("-1")
    else:
        t, h = ans
        print("{0} {1}".format(t, h))
    return True
    
def compare(diff, taro, hana):
    if len(taro) == 0 or len(hana) == 0:
        return None
    t = taro[0]
    h = hana[0]
    d = (t-h)*2
    if d < diff:
        return compare(diff, taro[1:], hana)
    if d == diff:
        return t, h
    else:
        return compare(diff, taro, hana[1:])
    
if __name__ == "__main__":
    while(solve1()):
        pass

Solution (Python):


while True:
    n, m = map(int, input().split())
    if not n:
        break
    taro = [int(input()) for i in range(n)]
    hanako = [int(input()) for i in range(m)]
    dif = sum(taro) - sum(hanako)
    ans = [-1]
    for i in taro:
        for j in hanako:
            if (i - j) * 2 == dif:
                if sum(ans) < 0 or i + j < sum(ans):
                    ans = [i, j]
    print(*ans)

Solution (Python):


while True:
    l = map(int,raw_input().split())
    if l == [0,0]:
        break
    else:
        check = 0
        taro = 0
        l1 = []
        for i in range(l[0]):
            n = int(raw_input())
            l1.append(n)
        l1.sort()
        l2 = []
        for i in range(l[1]):
            n = int(raw_input())
            l2.append(n)
        l2.sort()
        if sum(l1) < sum(l2):
            l3 = l1
            l1 = l2
            l2 = l3
            taro = 1
        if (sum(l1) - sum(l2))% 2 != 0:
            print -1
        else:
            a = (sum(l1) - sum(l2))/2
            for num in l1:
                if num - a in l2:
                    if taro == 1:
                        print num-a,num
                    else:
                        print num,num-a
                    check = 1
                    break
            if check == 0:
                print -1

Solution (Python):
while True:
    N, M = map(int, raw_input().split())
    if N == M == 0:
        break
    A = [int(raw_input()) for _ in xrange(N)]
    B = [int(raw_input()) for _ in xrange(M)]
    s = sum(A) - sum(B)
    A = set(A)
    B = set(B)
    if s % 2 != 0:
        print -1
        continue
    ans = []
    for a in A:
        if a - s / 2 in B:
            ans.append((a, a - s / 2))
    print ' '.join(map(str, min(ans, key=lambda x:x[0]+x[1]))) if len(ans) > 0 else -1

Solution (Python):
def search(t,st,h,sh):
    for ta in t:
        for ha in h:
            if st-ta+ha==sh-ha+ta: return ' '.join(map(str,[ta,ha]))
    return -1

while True:
    n,m = map(int,input().split())
    if n==m==0: break
    t = sorted([int(input()) for _ in range(n)])
    h = sorted([int(input()) for _ in range(m)])
    st,sh = sum(t),sum(h)
    r = search(t,st,h,sh)
    print(r)

Solution (Python):

def ans(t,h,t_s,h_s):
    for i in t:
        for j in h:
            if t_s - i + j == h_s - j + i:
                return str(i) + " " + str(j)
    return -1
while True:
    n, m = [int(x) for x in input().split()]
    
    if n == 0 and m == 0:
        break
    t = [int(input()) for i in range(n)]
    h = [int(input()) for i in range(m)]
    t_s = sum(t)
    h_s = sum(h)
    print(ans(t,h,t_s,h_s))

Solution (Python):
while 1:
    n,m = map(int,raw_input().split())
    if n == 0 and m == 0: break
    t = []
    h = []
    pair = []
    score = []
    lst = []
    for i in range(n):
        t.append(int(raw_input()))
    for i in range(m):
        h.append(int(raw_input()))    
    for i in range(n):
        
        for j in range(m):
            
            tmp_t = list(t)
            tmp_h = list(h)

            
            tmp = tmp_h[j]
            tmp_h[j] = tmp_t[i]
            tmp_t[i] = tmp
            
            
            if sum(tmp_t) == sum(tmp_h):
                pair.append([t[i],h[j]])
                score.append(t[i] + h[j])
    if pair == []:
        print "-1"
    else:
        lst = pair[score.index(min(score))]
        print lst[0],lst[1]

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)]

    
    if (sum(taro) + sum(hanako)) % 2 == 1:
        print(-1)
        continue
    half = (sum(taro) + sum(hanako)) // 2
    
    taro_ex = hanako_ex = half
    
    ex_flag = False

    for i in taro:
        for j in hanako:
            
            if sum(taro) + j -i == half and sum(hanako) + i - j == half:
                if i + j < taro_ex + hanako_ex:
                    taro_ex = i
                    hanako_ex = j
                    ex_flag = True

    if ex_flag:
        print(taro_ex, hanako_ex)
    else:
        print(-1)

Solution (Python):
from sys import stdin, stdout, stderr

while 1:
    n, m = map(int, stdin.readline().split())

    if n + m == 0:
        break

    taro = [int(stdin.readline()) for i in range(n)]
    hana = [int(stdin.readline()) for i in range(m)]

    tsum = sum(taro)
    hsum = sum(hana)

    if (tsum - hsum) % 2:
        print(-1)
        continue

    smin = 10000
    ans1, ans2 = -1, -1

    for i in range(n):
        for j in range(m):
            dif = taro[i] - hana[j]

            if tsum - dif == hsum + dif and taro[i] + hana[j] < smin:
                ans1, ans2 = taro[i], hana[j]
                smin = taro[i] + hana[j]

    if ans1 + ans2 >= 0:
        print(ans1, ans2)
    else:
        print(-1)

Solution (Python):
while 1:
    n, m = map(int, input().split())
    if not n:
        break
        
    t_card = [int(input()) for i in range(n)]
    h_card = [int(input()) for i in range(m)]
    total = [-1]
    dif = sum(t_card) - sum(h_card)
    for i in t_card:
        for j in h_card:
            if (i - j) * 2 == dif:
                if sum(total) < 0 or i + j < sum(total):
                    total = [i, j]
   
    print(*total)

Solution (Python):
if __name__ == "__main__":
    while True:
        n,m = list(map(int,input().strip().split()))
        if n ==0 and m ==0:break
        tarou = []
        hanako = []
        ans = (0,0)
        for _ in range(n): tarou.append(int(input()))
        for _ in range(m): hanako.append(int(input()))

        for i in range(n):
            for j in range(m):
                if sum(tarou[:i])+sum(tarou[i + 1:])+hanako[j] == sum(hanako[:j]) + sum(hanako[j+1:]) + tarou[i]:
                    if sum(ans) == 0:ans = (tarou[i],hanako[j])
                    elif sum(ans) > tarou[i]+ hanako[j]: ans = (tarou[i],hanako[j])
        if ans == (0,0):print(-1)
        else:print("%d %d" % (ans[0],ans[1]))

Solution (Python):
Answer = []

while True:
    inp = input().split()
    n = int(inp[0])
    m = int(inp[1])
    c = n**2 + m**2
    if c == 0:
        break

    T = []
    for t in range(n):
        inp = int(input())
        T.append(inp)

    H = []
    for h in range(m):
        inp = int(input())
        H.append(inp)

    Temp = []
    for i in range(n):
        for j in range(m):
            if sum(T)-2*T[i] == sum(H)-2*H[j]:
                TTemp = [T[i],H[j]]
                Temp.append(TTemp)
    if len(Temp) == 0:
        Answer.append(-1)
    else:
        S = sum(Temp[0])
        flg = 0
        for k in range(len(Temp)):
            if sum(Temp[k]) < S:
                flg = k
            S = min(S,sum(Temp[k]))
        Answer.append(str(Temp[flg][0])+" "+str(Temp[flg][1]))

for l in range(len(Answer)):
    print(Answer[l])

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n == m == 0: break
    c1 = [int(input()) for i in range(n)]
    c2 = [int(input()) for i in range(m)]
    diff = sum(c1) - sum(c2)
    if diff % 2 == 1:
        print(-1)
        continue
    for v1 in sorted(c1):
        v2 = v1 - diff//2
        if v2 in c2:
            print('{0} {1}'.format(v1, v2))
            break
    else:
        print(-1)

Solution (Python):
while True:
    N,M=map(int,input().split())
    if N==0 and M==0:
        break
    allCards=[]
    for i in range(N+M):
        allCards.append(int(input()))
                        
    Taro=allCards[:N]
    Hanako=allCards[N:]
    Tsum=sum(Taro)
    Hsum=sum(Hanako)
    diff=Tsum-Hsum
    tempsum=1e8
    Tchange=-1
    Hchange=-1
    for i in range(N):
        for j in range(M):
            tempdiff=(Taro[i]-Hanako[j])*2
            if diff==tempdiff:
                if(tempsum>Taro[i]+Hanako[j]):
                    tempsum=Taro[i]+Hanako[j]
                    Tchange=Taro[i]
                    Hchange=Hanako[j]
    if Tchange==-1:
        print(-1)
    else:
        print(Tchange,Hchange)

Solution (Python):
while True:
    n, m = map(int, input().split())
    if n == m == 0:
        quit()
    s1, s2 = [], []
    for i in range(n):
        s1.append(int(input()))
    for i in range(m):
        s2.append(int(input()))
    s1.sort()
    s2.sort(reverse=True)
    sum1 = sum(s1)
    sum2 = sum(s2)
    temp = 101
    for i in s1:
        for j in s2:
            if sum1 - i + j == sum2 - j + i:
                if temp > abs(i-j):
                    temp = abs(i-j)
                    ans = [i, j]
    if temp == 101:
        print(-1)
    else:
        print(ans[0], ans[1])

Solution (Python):
while True:
    n, m = map(int, raw_input().split())

    if n == 0 and m == 0:
        break

    taro = sorted([int(raw_input()) for _ in range(n)])
    hanako = sorted([int(raw_input()) for _ in range(m)])

    diff = sum(taro) - sum(hanako)

    flag = False

    def fnc():
        global flag
        for i in taro:
            for j in hanako:
                if (i - j) * 2 == diff:
                    print i, j
                    flag = True
                    return

    fnc()

    if not flag:
        print -1

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):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []
    while True:
        n,m = LI()
        if n == 0:
            break

        a = [I() for _ in range(n)]
        b = [I() for _ in range(m)]
        sa = sum(a)
        sb = sum(b)
        r = -1
        for ai in sorted(a, reverse=True):
            for bi in sorted(b, reverse=True):
                if sa - ai + bi == sb - bi + ai:
                    r = '{} {}'.format(ai, bi)
                    break
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())

Solution (Python):
while 1:
    n,m = list(map(int,input().split()))
    if not n and not m:break

    ln=sorted([int(input()) for _ in range(n)])
    lm=sorted([int(input()) for _ in range(m)])
    cd_n=set(ln)
    cd_m=set(lm)

    g=(sum(lm)-sum(ln))
    f=False
    if g%2==1:f=True
    else:g=g/2
    bf=False
    for i in cd_m:
        if f:break
        for j in cd_n:
            if i-j==g:bf=True
            if bf:break
        if bf:break
    if bf and not f:print(j,i)
    else:print("-1")

Solution (Python):
while(True):
    n, m = map(int, input().split())
    st = []
    sh = []
    if(n==0):
        break

    for i in range(n):
        st.append(int(input()))

    for i in range(m):
        sh.append(int(input()))

    
    

    ans = [100000, 100000]

    if (sum(st)-sum(sh))%2 == 1:
        print(-1)
        continue

    diff = (sum(st)-sum(sh))//2
    for i in range(len(st)):
        for j in range(len(sh)):
            if st[i]-sh[j] == diff and st[i]+sh[j] < sum(ans):
                ans = [st[i], sh[j]]

    if(ans == [100000, 100000]):
        print(-1)
    else:
        print(str(ans[0])+" "+str(ans[1]))

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

Solution (Python):
import sys

while True:
    n, m = map(int, sys.stdin.readline().split())
    if n == 0 and m ==0:
        break
    
    taro = []
    for i in xrange(n):
        x = int(sys.stdin.readline())
        
        taro.append(x)
    hanako = []
    for i in xrange(m):
        x = int(sys.stdin.readline())
        
        hanako.append(x)
    
    sum_taro = sum(taro)
    sum_hanako = sum(hanako)
    
    diff = -(sum_taro - sum_hanako) / 2.0
    if diff != int(diff):
        print -1
        continue
    MAX = max(taro + hanako) + 1
    result = MAX
    for t in taro:
        if t + diff in hanako:
            if result > t:
                result = t
    if result != MAX:
        print result, int(result + diff)
    else:
        print -1

Solution (Python):
while True:
    n,m=map(int,raw_input().split())
    if n==m==0:break
    taro=[input() for i in range(n)]
    hana=[input() for i in range(m)]
    L=[]
    sumta=sum(taro)
    sumha=sum(hana)
    for i in range(n):
        temp1=sumta-taro[i]
        temp2=sumha+taro[i]
        for j in range(m):
            if temp1+hana[j]==temp2-hana[j]:
                L.append((taro[i]+hana[j],taro[i],hana[j]))
    if L<>[]:
        L.sort()
        print L[0][1],L[0][2]
    else:
        print -1

Solution (Python):
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	taro = sorted([int(raw_input()) for i in range(n)])
	hana = [int(raw_input()) for i in range(m)]
	d = sum(hana) - sum(taro)
	t,h = 101,101
	for i in taro:
		if d/2.0 + i in hana:
			t,h = i,d/2 + i
			break
	print "%d %d"%(t,h) if t < 101 else -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)]
    a.sort()
    b.sort()
    c=0
    d=0
    for i in range(len(a)):
        if d==1:
            break
        for j in range(len(b)):
            if sum(a)-a[i]+b[j]==sum(b)+a[i]-b[j]:
                print(a[i],b[j])
                d=1
                break
            else:
                c+=1
    if c==len(a)*len(b):
        print('-1')

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)]
    d = sum(taro)-sum(hanako)
    def search():
       for i in taro:
           for j in hanako:
               if (i-j)*2 == d: 
                   print(i,j)
                   return
       print(-1)
    search()

Solution (Python):
while True:
    n,m=map(int,input().split())
    if n==m==0:
        break
    ta=[int(input()) for i in range(n)]
    ha=[int(input()) for i in range(m)]
    taro=sorted(ta)
    hana=sorted(ha)
    taha=(sum(ta)-sum(ha))/2
    kai=0
    if taha<0:
        for i in range(len(taro)):
            if taro[i]+abs(taha) in hana:
                kai=1
                print(taro[i],int(taro[i]+abs(taha)))
                break
    else:
        for i in range(len(taro)):
            if taro[i]-abs(taha) in hana:
                kai=1
                print(taro[i],int(taro[i]-abs(taha)))
                break
    if kai!=1:
        print('-1')

Solution (Python):
while True:
    n,m=map(int, input().split())
    if(n==0):
        break
    cn=[]
    cm=[]
    
    for i in range(n):
        cn.append(int(input()))
    for i in range(m):
        cm.append(int(input()))

    k=0
    for i in range(n):
        for j in range(m):
            cn[i],cm[j]=cm[j],cn[i]
            if(sum(cn)==sum(cm)):
                print(cm[j],cn[i])
                k+=1
                break
            else:
                cn[i],cm[j]=cm[j],cn[i]
        else:
            continue
        break
    
    if(k!=1):
        print(-1)

Solution (Python):
while True:
    n,m = map(int,input().split())
    if n == 0:
        exit()
    t = []
    h = []
    num = []
    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]):
                num.append([t[i] + h[j], t[i], h[j]])
    num = sorted(num)
    if len(num) != 0:
        print(str(num[0][1]) + " " + str(num[0][2]))
    else:
        print(-1)