Club Room Project (Small)

Given N rooms in a row and M wall-breaking actions, count how many rooms remain after all actions merge neighboring rooms.

Easy3Union-findImplementationNo attempts yetTime limit1sMemory limit512 MB

Problem

Byeongchan wanted a club room, so he asked the LINK office and got a chance to receive one of NN rooms. The building is a single straight corridor with NN rooms in a row. The leftmost room is numbered 1, the numbers grow by 1 toward the right, and the rightmost room is numbered NN. Between every pair of neighbouring rooms there is one wall that separates them.

Plenty of other people want a club room too. Rooms were plentiful, so Byeongchan was not worried.

Then the Big Jongbin Villain showed up and started knocking down the walls of the building. The villain follows these rules.

  • The villain picks two rooms with x<yx < y, then knocks down every wall that lies between room xx and room yy.
  • Once the wall between two rooms is gone, the two rooms become one room.
  • If a wall is already down, the villain passes over it and moves on to the next wall.
  • The villain does not want the building to collapse, so the wall on the left of room 1 and the wall on the right of room NN, the two walls that face the outside, are never touched.

As the number of rooms dropped, Byeongchan grew nervous. To work out his chance of getting a club room he first needs the number of rooms that are left. Given the number of actions MM and the starting number of rooms NN, find how many rooms remain after every action is done.

Input

The first line contains a positive integer NN (2N1002 \le N \le 100), the starting number of rooms. The second line contains a non-negative integer MM (0M1000 \le M \le 100), the number of actions. Each of the next MM lines describes one action with two positive integers xx and yy (1x<yN1 \le x < y \le N), meaning that every wall between room xx and room yy is knocked down.

The villain is clumsy, so the same action may appear several times.

Output

Print the number of rooms that remain after every action is done, on one line.

Hint

Take N=5N = 5 with the actions (1,2)(1, 2) and (2,4)(2, 4). The first action merges rooms 1 and 2, leaving (1, 2), (3), (4), (5). The second action merges rooms 2, 3 and 4, leaving (1, 2, 3, 4) and (5). So 2 rooms remain.