Charging
题号:NC214017
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 128 M,其他语言256 M
64bit IO Format: %lld

题目描述

Xxy is the king of the universe. In order to resist the invasion, he ordered the construction of many space warships.Now,he wants to charge his space ships.

He has N space ships.The N ships are numbered from 1 to N and lined up in order.

Xxy has M charging plans.The i-th plan is describe by two positive integers li,ri.It means in this plan, he will charge the ships numbered from li to ri.

Xxy will choose some of these plan.If he totally choose tot plans,x is the number of ships that charged in every plans.Xxy want to maximize the value of min(tot,x).

输入描述:

The first line contains two positive integers N and M(N,M≤300000).

The next M lines,each containing two positive integers li and ri.(li≤ri)

输出描述:

The output contains a positive integer. The maximal value of min(tot,x).

示例1

输入

复制
3 3
1 3
2 2
1 2

输出

复制
2