import sys

def getMoneySpent(keyboards, drives, s):
    res = -1
    possibleCost = list()
    for k in keyboards:
        for d in drives:
            possibleCost.append(k+d)

    possibleCost.sort()

    for i in possibleCost:
        if(i <= s):
            res = i
        else:
            break

    return res

s,n,m = input().strip().split(' ')
s,n,m = [int(s),int(n),int(m)]
keyboards = list(map(int, input().strip().split(' ')))
drives = list(map(int, input().strip().split(' ')))
#  The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
moneySpent = getMoneySpent(keyboards, drives, s)
print(moneySpent)
1b5aae3fb319defb9c9209dfb42ade35b39c9564
<mask token>


def getMoneySpent(keyboards, drives, s):
    res = -1
    possibleCost = list()
    for k in keyboards:
        for d in drives:
            possibleCost.append(k + d)
    possibleCost.sort()
    for i in possibleCost:
        if i <= s:
            res = i
        else:
            break
    return res


<mask token>

<mask token>


def getMoneySpent(keyboards, drives, s):
    res = -1
    possibleCost = list()
    for k in keyboards:
        for d in drives:
            possibleCost.append(k + d)
    possibleCost.sort()
    for i in possibleCost:
        if i <= s:
            res = i
        else:
            break
    return res


<mask token>
print(moneySpent)

<mask token>


def getMoneySpent(keyboards, drives, s):
    res = -1
    possibleCost = list()
    for k in keyboards:
        for d in drives:
            possibleCost.append(k + d)
    possibleCost.sort()
    for i in possibleCost:
        if i <= s:
            res = i
        else:
            break
    return res


s, n, m = input().strip().split(' ')
s, n, m = [int(s), int(n), int(m)]
keyboards = list(map(int, input().strip().split(' ')))
drives = list(map(int, input().strip().split(' ')))
moneySpent = getMoneySpent(keyboards, drives, s)
print(moneySpent)

import sys


def getMoneySpent(keyboards, drives, s):
    res = -1
    possibleCost = list()
    for k in keyboards:
        for d in drives:
            possibleCost.append(k + d)
    possibleCost.sort()
    for i in possibleCost:
        if i <= s:
            res = i
        else:
            break
    return res


s, n, m = input().strip().split(' ')
s, n, m = [int(s), int(n), int(m)]
keyboards = list(map(int, input().strip().split(' ')))
drives = list(map(int, input().strip().split(' ')))
moneySpent = getMoneySpent(keyboards, drives, s)
print(moneySpent)

import sys

def getMoneySpent(keyboards, drives, s):
    res = -1
    possibleCost = list()
    for k in keyboards:
        for d in drives:
            possibleCost.append(k+d)

    possibleCost.sort()

    for i in possibleCost:
        if(i <= s):
            res = i
        else:
            break

    return res

s,n,m = input().strip().split(' ')
s,n,m = [int(s),int(n),int(m)]
keyboards = list(map(int, input().strip().split(' ')))
drives = list(map(int, input().strip().split(' ')))
#  The maximum amount of money she can spend on a keyboard and USB drive, or -1 if she can't purchase both items
moneySpent = getMoneySpent(keyboards, drives, s)
print(moneySpent)