Painting the Balls

Given M range-painting operations used in order with unknown colors, count how many distinct final black/white ball colorings are possible.

Medium7Dynamic programmingBit manipulationCombinatoricsNo attempts yetTime limit2sMemory limit512 MB

Problem

NN balls sit in a row. A ball can be painted black or white, and every ball is white at the start. The leftmost ball is ball 1, and the balls are numbered in order from left to right.

Today you want to paint the balls. A machine does the painting, and it reads two integers LL and RR. The machine paints ball LL through ball RR entirely in one color, either white or black.

You used the machine MM times in total, and you know every LL and RR you gave it. You forgot which color each use painted.

Write a program that counts how many color combinations can appear after all MM uses of the machine.

Input

The first line contains the number of balls NN and the number of machine uses MM. (1N10001 \le N \le 1000, 1M501 \le M \le 50)

Each of the next MM lines contains the LL and RR given to the machine, in the order the machine was used. (1LRN1 \le L \le R \le N)

Output

Print the number of color combinations that can appear. The answer is at most 26312^{63}-1.