There are three types of animals in the animal kingdom A, B, C, three types of animal food chain constitute an interesting ring.
A food B, B eat C, C eat A.
Animals prior N, number to 1-N.
Each animal is A, B, C in kind, but we do not know it in the end is what kind of.
Some people describe this relationship N animal food chain formed by two different ways:
The first argument is "1 XY", represents the X and Y are similar.
The second argument is "2 XY", X represents eat Y.
This person for N animals, with the above two statements, one sentence by sentence to say K, K this sentence some true, some false.
When one of the following three words, this sentence is a lie, the truth is otherwise.
1) if the current true, then some of the previous conflicts, is lie;
2), then the current X or Y is larger than N, is lie;
3) X represents eat, then the current X, is lie.
Your task is given according to the total number of N and K words, the output of lies.
Input Format
The first line of two integers N and K, separated by a space.
K The following three lines each is a positive integer D, X, Y, separated by a space between the two numbers, where D indicates the type of argument.
If D = 1, it indicates that X and Y are similar.
If D = 2, then X represents eat Y.
Output Format
Only one integer representing the number of lies.
data range
1≤N≤500001≤N≤50000,
0≤K≤1000000≤K≤100000
Sample input:
100 7
1 101 1
2 1 2
2 2 3
2 3 3
1 1 3
2 3 1
1 5 5
Sample output:
3