Problem Statement

There is a family consisting of person 1, person 2, ..., and person N. For i≥2, person i's parent is person pi.

They bought insurance M times. For i=1,2,...,M, person xi bought the i-th insurance, which covers that person and their descendants in the next yi generations.

How many people are covered by at least one insurance?

Constraints

  • 2≤N≤3×105
  • 1≤M≤3×105
  • 1≤pi≤i−1
  • 1≤xi≤N
  • 1≤yi≤3×105

All input values are integers.

Input

The input is given from Standard Input in the following format:

The first line contains two integers N and M, separated by a space.

The i-th line (1≤i≤M) of the following M lines contains two integers xi and yi, separated by a space.

Output

Print the number of people who are covered by at least one insurance.

Sample Input 1

5 2
1 2
2 3

Sample Output 1

5

Sample Input 2

10 3
1 2
2 3
3 1

Sample Output 2

9

Sample Input 3

3 1
1 3

Sample Output 3

3

原文地址: https://www.cveoy.top/t/topic/pB1z 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录