#Q5. 「一本通 1.1 例 5」智力大冲浪

「一本通 1.1 例 5」智力大冲浪

Description

Xiao Wei signed up for a quiz show on CCTV. This challenge attracted many participants, and to commend everyone's courage, the host first rewarded each contestant with mm yuan. Don't get too happy yet! Because this money isn't necessarily all yours?! The host then announced the rules of the competition:

First, the competition time is divided into nn periods. The host also provided many mini-games, each of which must be completed before its specified deadline tit_i. If a game is not completed before the deadline, a portion of the reward money mm yuan will be deducted, with wiw_i being a natural number, and the amount deducted varies for different games. Of course, each game itself is very simple, ensuring that every contestant can complete it within one period and must start at the beginning of a period. The host just wants to test how each contestant arranges the order of playing the games. As a contestant, Xiao Wei is eager to win the championship and, of course, to earn the most money! Note: The competition will absolutely not leave contestants losing money!

Input Format

The input consists of four lines.

The first line is mm, representing the initial amount of money rewarded to each contestant;

The second line is nn, indicating there are nn mini-games;

The third line contains nn numbers, representing the deadlines for games 11 to nn;

The fourth line contains nn numbers, representing the penalty amounts for games 11 to nn if not completed before the deadline.

Output Format

The output consists of a single line, indicating the maximum amount of money Xiao Wei can win.

Sample 1

10000
7
4 2 4 3 1 4 6
70 60 50 40 30 20 10

9950

Data Range and Hint

For 100%100\% of the data, n500n\le 500, and 1tin1\le t_i\le n.