#P10935. Minimum Total Brightness

    ID: 12983 Type: Default 1000ms 256MiB

Minimum Total Brightness

Minimum Total Brightness

In our galaxy there are countless stars, but we only focus on the brightest ones. Each star's brightness is represented by a positive integer, and the larger the number, the brighter the star. The minimum brightness for any star is \(1\).

We are given \(N\) stars and \(M\) pairs of relative brightness relationships between certain stars. Each pair is given as two integers \(u\) and \(v\) indicating that the brightness of star \(u\) is strictly greater than that of star \(v\). In mathematical terms, this relationship is represented as:

[ b_u \ge b_v + 1, \quad \forall (u,v) \text{ given}, ]

Your task is to assign a brightness (a positive integer not less than \(1\)) to each star such that all the above constraints are satisfied, and the total sum of brightness values over all \(N\) stars is minimized. Output this minimum sum.

inputFormat

The first line contains two integers \(N\) and \(M\) where \(N\) is the number of stars and \(M\) is the number of known brightness relationships.

The next \(M\) lines each contain two integers \(u\) and \(v\), representing that the brightness of star \(u\) is strictly greater than that of star \(v\) (i.e., \(b_u > b_v\)).

outputFormat

Output a single integer, the minimum total brightness sum for all \(N\) stars.

sample

3 2
2 1
3 1
5