Under construction

Still being built. Things may change

Tetrooj Box

Time limit5sMemory limit1024 MB

Summary
Blocks are dropped onto a base of width b, each landing on the base or the highest block below it. The task is to find the final tallest column height.
Level

Easy3 of 10

Topics
Array, Simulation
Solved
No attempts yet

Problem

Dr. Orooji's children have played Tetris but are not willing to help Dr. O with a related problem. Dr. O's children don't realize that Dr. O is lucky to have access to 100+ great problem solvers and great programmers today!

Dr. O knows the length of the base for a 2D box and wants to figure out the needed height for the box. Dr. O will drop some 2D blocks (rectangles) on the base. A block will go down until it lands on the base or is stopped by an already-dropped block (i.e., it lands on that block). After all the blocks have been dropped, the needed height for the box is determined by the tallest column. See the pictures in the hint section.

Input

The first input line contains two integers: bb (1≤b≤1001 \le b \le 100), the length of the base, and rr (1≤r≤501 \le r \le 50), the number of blocks. Each of the next rr lines contains three integers: a block's horizontal length hh (1≤h≤1001 \le h \le 100), its vertical length vv (1≤v≤1001 \le v \le 100), and cc (c≥1c \ge 1), the leftmost column the block is dropped into. The values of hh and cc are such that the block does not go beyond the base, i.e., (c+h−1)≤b(c + h - 1) \le b.

Output

Print the needed height for the box. The tallest column is the height.

Hint

Examples2

  1. Example 1

    Input
    10 4
    2 3 1
    4 2 2
    1 7 6
    1 3 4
    
    Expected output
    8
    
  2. Example 2

    Input
    10 3
    3 4 8
    8 2 1
    1 1 3
    
    Expected output
    7