Jaime, a friendly guinea pig, and their clever friend Churro, also a guinea pig, have won the International Cavy Programming Contest. To celebrate their victory, they are organizing a party. They have $$$F$$$ other friends, numbered from $$$1$$$ to $$$F$$$, and sent invitations to $$$N$$$ of them (due to some budget limitations). Each invitation may cover several guests, such as the invited friend's family.
Each invited friend either accepted the invitation and specified their group's schedule, declined the invitation, or gave a tentative response that depends on whether another friend attends.
If a tentative response depends on a friend who declined, on a friend who was not invited, or on a circular chain of tentative responses, that friend will not attend.
Jaime and Churro will prepare a party playpen for the invited groups. At the minute when a group leaves, it no longer occupies the playpen, so its space can be used by groups arriving at that same minute. Determine the minimum guest capacity required for the playpen to accommodate all attending groups, excluding Jaime and Churro.
The first line contains two integers $$$F$$$ and $$$N$$$ ($$$1 \leq F \leq 10^{9}$$$, $$$1 \leq N \leq \min(10^{5}, F)$$$), the total number of their friends and the number of invitations, respectively.
Each of the next $$$N$$$ lines contains two integers $$$k_i$$$ and $$$p_i$$$ ($$$1 \leq k_i \leq F$$$, $$$1 \leq p_i \leq 10^{5}$$$). These values indicate that the $$$i$$$-th invitation was sent to friend $$$k_i$$$ and covers a group of exactly $$$p_i$$$ guests, including friend $$$k_i$$$. All values $$$k_i$$$ are distinct.
Each of the next $$$N$$$ lines contains the response to the corresponding invitation, in the same order as the invitations. A response has one of the following forms:
Print one integer: the minimum guest capacity required for the party playpen.
10 51 12 23 37 19 1A 1 3DT 2T 1T 7
3
Explanation for example 1
Friend $$$1$$$ accepted the invitation, which covers only that friend. Friend $$$2$$$ declined, so friend $$$3$$$, whose response depends on friend $$$2$$$, does not attend.
Friend $$$7$$$ depends on friend $$$1$$$, and friend $$$9$$$ depends on friend $$$7$$$. Therefore, friends $$$1$$$, $$$7$$$, and $$$9$$$ all attend from minute $$$1$$$ to minute $$$4$$$. Their invitations cover $$$1$$$ guest each, so the maximum number of guests in the playpen at the same time is $$$3$$$.
| Название |
|---|


