The company has N network systems S1,S2,…,SN and M networks W1,W2,…,WM that connect them. Each system has a priority, and every network carries data only from a higher-priority system to a lower-priority one. That is, if a network carries data from SA to SB, then A<B.
The networks have become too tangled, so the company decided to tidy them up. For three systems SA, SB, and SC, if there is a network from SA to SB and a network from SB to SC, the two are merged into a single network from SA to SC. The two original networks disappear and one new network appears. Several networks may connect the same pair of systems, and each of them counts as a separate network.
The company repeats this simplification to reduce the number of networks as much as possible. Find the number of networks that remain.