A clay mine on Mars digs up red carbon-silicon clay and presses it into plates that are easy to transport. Every plate has the same standard width and thickness, but plates can differ in height and in material quality. There are 1000 quality classes, and plates are produced in heights of 1, 2, ..., 500000mm. The price of a plate depends only on its material quality, not on its height: a plate made of class q material costs q galactars.

A galactic container ship carries these plates. Its cargo hold is a hall with M rails mounted in parallel in the floor; each rail can hold exactly one plate. The hold has a slanted ceiling: at one end it is 1mm high and at the other end it is Mmm high. That is, the ceiling above the rail numbered n is exactly nmm high, so that rail can hold only a plate whose height is at most n.
A pile of plates waiting to be shipped sits at the dock. The captain wants to load cargo of the greatest possible total value, but is limited by the size of the hold (the plates cannot be trimmed). The experienced crew always chooses the load optimally, following the captain's wishes. Determine how much the captain must pay for the optimal load.
Write a program that:
The first line contains two natural numbers M and N separated by a space (1≤M≤500000, 0≤N≤1000000). M is the length and the maximum height of the hold, and at the same time the number of rails; N is the number of plates on the pile. Each of the next N lines describes one plate as two natural numbers w and h separated by a space (1≤w≤1000, 1≤h≤500000): w is the quality class of the plate's material and h is the plate's height in millimeters. Note that the pile may contain plates taller than the maximum height allowed in the hold.
Print a single integer: the value of the optimal load.