

import os
import sys


def getMoneySpent(keyboards, drives, b):
    keyboards.sort()
    drives.sort()

    max_price = 0

    if(keyboards[0] + drives[0] > b):
        return -1

    for k in keyboards:
        for d in drives:
            if k + d >= max_price and k + d <= b:
                max_price = k + d

    return max_price


if __name__ == '__main__':
    bnm = input().split()

    b = int(bnm[0])

    n = int(bnm[1])

    m = int(bnm[2])

    keyboards = list(map(int, input().rstrip().split()))

    drives = list(map(int, input().rstrip().split()))

    print(getMoneySpent(keyboards, drives, b))

05e33ec5cf7858c45936c0f4df4de01a9e2d4264
<mask token>

<mask token>


def getMoneySpent(keyboards, drives, b):
    keyboards.sort()
    drives.sort()
    max_price = 0
    if keyboards[0] + drives[0] > b:
        return -1
    for k in keyboards:
        for d in drives:
            if k + d >= max_price and k + d <= b:
                max_price = k + d
    return max_price


<mask token>

<mask token>


def getMoneySpent(keyboards, drives, b):
    keyboards.sort()
    drives.sort()
    max_price = 0
    if keyboards[0] + drives[0] > b:
        return -1
    for k in keyboards:
        for d in drives:
            if k + d >= max_price and k + d <= b:
                max_price = k + d
    return max_price


if __name__ == '__main__':
    bnm = input().split()
    b = int(bnm[0])
    n = int(bnm[1])
    m = int(bnm[2])
    keyboards = list(map(int, input().rstrip().split()))
    drives = list(map(int, input().rstrip().split()))
    print(getMoneySpent(keyboards, drives, b))

import os
import sys


def getMoneySpent(keyboards, drives, b):
    keyboards.sort()
    drives.sort()
    max_price = 0
    if keyboards[0] + drives[0] > b:
        return -1
    for k in keyboards:
        for d in drives:
            if k + d >= max_price and k + d <= b:
                max_price = k + d
    return max_price


if __name__ == '__main__':
    bnm = input().split()
    b = int(bnm[0])
    n = int(bnm[1])
    m = int(bnm[2])
    keyboards = list(map(int, input().rstrip().split()))
    drives = list(map(int, input().rstrip().split()))
    print(getMoneySpent(keyboards, drives, b))



import os
import sys


def getMoneySpent(keyboards, drives, b):
    keyboards.sort()
    drives.sort()

    max_price = 0

    if(keyboards[0] + drives[0] > b):
        return -1

    for k in keyboards:
        for d in drives:
            if k + d >= max_price and k + d <= b:
                max_price = k + d

    return max_price


if __name__ == '__main__':
    bnm = input().split()

    b = int(bnm[0])

    n = int(bnm[1])

    m = int(bnm[2])

    keyboards = list(map(int, input().rstrip().split()))

    drives = list(map(int, input().rstrip().split()))

    print(getMoneySpent(keyboards, drives, b))
