#P1263. Check in II

Check in II

题目描述

Dr Lu says we need to have more easy problems so that every one attending the contest can solve them. Though the problem above is easy enough, he also wants some more easy problems, so this problem is set.

As the title of the problem indicates, this is also a check in problem, but we have made one above, so this problem may be harder than the problem Check in I.

Suppose we are in the canteen of QLU. There are many tables we can get foods, and for every table, there are many promotion strategies to sell the food well, which we can think that all the strategies are like: Buy xx piece of food then give yy additional piece of food as gifts.

For example, suppose the strategy for some table is Buy 33 piece of food then give 11 additional piece of food as a gift, which means if you buy 33 piece of food then you can get 11 piece of food for free.

Now you have nn yuan, please calculate the maximum number of food you can get.

It is guaranteed that every table can afford your purchases.

输入格式

The first line of the input contains two positive integers n,mn,m which indicates that now you have nn yuan and there are mm tables in the canteen(1n,m100)(1\le n,m\le100).

Then followed mm lines each line contains the description of the table which contains three positive integers xi,yi,zix_i,y_i,z_i indicating the cost of one piece of food and the strategy: Buy yiy_i piece of food then give ziz_i additional piece of food as gifts.

It is guaranteed that for each 1xin1\le x_i \le n and 1ziyi1001\le z_i \le y_i \le 100

输出格式

The maximum number of food you can get.

样例

5 3 
1 3 2 
4 2 1 
5 1 1
7

提示

For the test case, we can buy the food in the first table, so we can get 7 piece of food.