#P475. 【例86.2】 01背包问题

【例86.2】 01背包问题

Description

A traveler has a backpack that can hold at most MM kilograms. There are nn items available, with weights W1W_1, W2W_2, ..., WnW_n and values C1C_1, C2C_2, ..., CnC_n. Find the maximum total value the traveler can obtain.

Input Format

The first line contains two integers: MM (backpack capacity, M200M ≤ 200) and NN (number of items, N30N ≤ 30).
Lines 22 to N+1N+1 each contain two integers WW and CC, representing the weight and value of each item.

Output Format

A single line containing one number, representing the maximum total value.

Sample

10 4
2 1
3 3
4 5
7 9
12