Selling CPUs

Sell up to c CPUs across m ordered merchants, each paying p_i for exactly i CPUs in one deal, to maximize total money.

Medium5Dynamic programmingGreedyInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

You got a job at a CPU factory. After a hard month of labor your boss paid you with cc identical CPUs instead of cash, because the company is short on money right now.

You cannot live on CPUs alone, so you want to sell them at the market and buy what you need with the proceeds. The market is strict about how you may do business. You may enter the market once, you may trade with each merchant only once, and you have to visit the merchants in a fixed order. The organizers numbered the merchants from 11 to mm, and you must visit them in that order. Every merchant has his own price for each quantity of CPUs.

At a merchant you can walk past without selling anything, or you can sell some of the CPUs you still hold in a single deal.

Input

The first line has two integers cc and mm (1c,m1001 \le c, m \le 100), the number of CPUs and the number of merchants.

Each of the next mm lines describes one merchant, in order from merchant 11 to merchant mm. Such a line has cc integers p1,,pcp_1, \dots, p_c (1pi1051 \le p_i \le 10^5), where pip_i is the amount of money that merchant pays for ii CPUs.

Output

Print the maximum amount of money you can make by selling the CPUs you have.

You do not have to sell all of them.