K. Elder is prohibited from participating in the ICPC——老登禁止参加 ICPC

    传统题 1000ms 256MiB

Elder is prohibited from participating in the ICPC——老登禁止参加 ICPC

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Statement

Among contemporary college students, there's a popular competition: the International Chuuni Performance Contest (ICPC).

Don't be intimidated by the name; this isn't a competition you can win by simply shouting "Dark Flame Palm." It's a serious (yet not-so-serious) event that requires imagination, expressiveness, and even a bit of self-confidence.

Timothy, a passionate young man, wanted to enter the competition. However, as he carefully read the rules, he discovered a shocking clause: high school students (minors) and university graduates were prohibited from participating as official competitors. In other words, if he insisted on participating, he would only be a "friendly participant," and no matter how good his performance was, he wouldn't receive a medal.

"So what's the point of coming here?!" Timothy grumbled as he sat at his computer, frantically researching the competition requirements for various countries. He soon discovered the key: the high school and college graduation ages differed from country to country.

As long as his age was greater than or equal to the high school graduation age in a given country, and strictly less than the college graduation age in that country, he could legitimately become a competitor.

So the question arose: Timothy's actual age this year is xx. There are yy ICPC competitions around the world. He needs to know which ones he can legitimately win, rather than just joining in the fun.

Now, please help him calculate how many of these places he can compete for that glittering medal.

Input

The first line contains an integer x(1x109)x(1 \leq x \leq 10^9), representing Timothy's age. (Yes, the question guarantees that he can theoretically live to 10910^9 years.)

Second line: An integer y(1y105)y(1 \leq y \leq 10^5), representing the number of matches found.

The next yy lines: Each line contains two integers ai,bi(1ai,bi109)a_i,b_i(1 \leq a_i,b_i \leq 10^9), where aia_i represents the age of high school graduation in that country, and bib_i represents the age of undergraduate graduation in that country.

Output

Output a line containing a single number, indicating the number of contests Timothy can participate in.

Samples

20
4
18 22
21 25
16 20
19 30
2

Notes

For the first example, Timothy is 20 years old. Let's look at the rules for four countries:

  1. Country A: High school graduates age 18, undergraduate graduates age 22; Timothy's age falls within the 1820<2218 \leq 20 < 22 range. He can participate and win a medal.
  2. Country B: High school graduates age 21, undergraduate graduates age 25; Timothy is still a year away from turning 21. Sorry, he's not old enough and should come back next year.
  3. Country C: High school graduates age 16, undergraduate graduates age 20; note that this requires them to be strictly less than 20 years old, and Timothy is exactly 20; one year short, he's completely out of the running.
  4. Country D: High school graduates age 19, undergraduate graduates age 30; Timothy's age falls within the 1920<3019 \leq 20 < 30 range. He can participate and should have no problem winning a medal!

Thus, Timothy was ultimately able to compete as a regular competitor in ICPC competitions in two countries and win prizes.

2025 JSUT Collegiate Programming Contest 江苏理工学院新生赛-同步赛

未参加
状态
已结束
规则
ACM/ICPC
题目
15
开始于
2025-11-8 12:00
结束于
2025-11-8 17:00
持续时间
5 小时
主持人
参赛人数
15