LaLa's younger sister LiLi is helping LaLa cast the spirit summoning magic.
While LaLa was asleep, LiLi had already built a prototype of the spirit to summon. The spirit consists of N magic joints which allow any magic bars attached to them to freely move around them, and M magic bars of various colors, each of which connects two magic joints and whose length can be adjusted to any non-negative real number before the summoning (but not after).
When it comes to spirit summoning, LaLa has a far higher standard than LiLi. Of course, LaLa was not satisfied with LiLi's work whatsoever. LaLa would like to fabulize the prototype by getting rid of some magic bars so that
Write a program that computes the degree of freedom of the spirit fabulized by LaLa.
The input describes the prototype spirit made by LiLi and is given in the following format:
N M
u_0 v_0 c_0
u_1 v_1 c_1
⋮
u_M−1 v_M−1 c_M−1
where N is the number of magic joints, numbered from 0 to N−1, M is the number of magic bars, and for each integer 0≤i<M, the i-th magic bar has color c_i and connects the magic joint u_i and v_i.
The input satisfies the following constraints:
Note that there can be multiple magic bars connecting the same pair of magic joints.
The output should be a single integer equal to the degree of freedom of the spirit fabulized by LaLa.
Intuitively, the degree of freedom is the number of axis of motions preserving edge lengths of the spirit embedded on a plane.
More formally, let E be an assignment of planar coordinates (we'll call this an embedding) to all magic joints of a spirit. Note that such an embedding can be identified with an element in R2N by concatenating all coordinates, where N is the number of magic joints.
Let C(E) be the set of embeddings continuously reachable from E as an element of R2N while preserving edge lengths. i.e. for each element E′ of C(E) and each magic bars of the spirit connecting magic joints u and v, the euclidean distance between u and v must be the same in E and E′.
The degree of freedom of E is the minimum non-negative integer k such that there exists a continuous bijective mapping F:D→C(E) where D is a connected subset of Rk.
The degree of freedom of a spirit is the maximum degree of freedom over all such embeddings E.
The following illustrate the spirit fabulized by LaLa along with one of the optimal embedding and the mapping F for each sample tests in order.
k=5, D=R2×\[0,2π)×R2
F:(x_0,x_1,x_2,x_3,x_4)↦⟨(x_0,x_1),(x_0,x_1)+(cosx_2,sinx_2),(x_3,x_4)⟩
The following illustrates the 5 degrees of freedom associated with each variables.

k=3, D=R2×\[0,2π)
F:(x_0,x_1,x_2)↦⟨(x_0,x_1),(x_0,x_1)+(cosx_2,sinx_2),(x_0,x_1)+(cos(3π+x_2),sin(3π+x_2))⟩
The following illustrates the 3 degrees of freedom associated with each variables.

k=4, D=R2×(((0,2]×\[0,2π))∪({0}×\[0,π)))
F:(x_0,x_1,x_2,x_3)↦⟨P_0,P_0+2x_2P_1+1−4x_22P_2,P_0+x_2P_1,P_0+2x_2P_1−1−4x_22P_2⟩
where P_0=(x_0,x_1),P_1=(cosx_3,sinx_3) and P_2=(sinx_3,−cosx_3).
The following figure on the left illustrates the 4 degrees of freedom associated with each variables. Note that the motion associated with the variable x_2 is non-rigid. The one on the right illustrates the motion associated with x_2 in detail.

k=6, D=R2×\[0,2π)4
F:(x_0,x_1,x_2,x_3,x_4,x_5)↦⟨P_0,P_1,P_2,P_3,P_4⟩
where P_0=(x_0,x_1) and P_i=P_i−1+(cosx_i+1,sinx_i+1) for all integers 1≤i≤4.
The following illustrates the 6 degrees of freedom associated with each variables.
