#CCBCHBAHAI0000091. Electronics Shop

    ID: 1009 Loại: Thông thường 2000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 1 Đăng bởi: Nhãn>Programming language basicsStatic arraysIteration techniquesImplementation techniquesWorking with numbersInteger arithmetic

Electronics Shop

Electronics Shop

Source: HackerRank

Version: Phuoc Hung OJ Extended

Problem

Given budget BB, keyboard prices k0,…,kn−1k_0,\ldots,k_{n-1}, and USB-drive prices d0,…,dm−1d_0,\ldots,d_{m-1}, buy exactly one item from each list.

Find

M=max⁡{ki+dj∣ki+dj≤B}.M=\max\{k_i+d_j\mid k_i+d_j\le B\}.

If no valid pair exists, print −1-1.

Input

The first line contains BB, nn, and mm. The next two lines contain keyboard and USB-drive prices.

Output

Print the maximum affordable total, or −1-1 if no pair can be bought.

Subtask

Subtask 1 (20 points): 1≤n,m≤101\le n,m\le10, 1≤B,ki,dj≤1061\le B,k_i,d_j\le10^6.

Subtask 2 (30 points): 1≤n,m≤1001\le n,m\le100, 1≤B,ki,dj≤1061\le B,k_i,d_j\le10^6.

Subtask 3 (50 points): 1≤n,m<10001\le n,m<1000, 1≤B,ki,dj≤1061\le B,k_i,d_j\le10^6.

Example

Input

10 2 3
3 1
5 2 8

Output

9

Explanation

The result follows directly from the mathematical definition above.