Monthly Railway Pass

No attempts yetTime limit2sMemory limit1024 MB

Problem

There are NN cities in Bitlandia. Some pairs of cities are connected by a train line or a bus line, and every connection is bidirectional.

Marijonas is planning a month-long vacation in Bitlandia. He wants to use trains as much as possible, so he bought a monthly railway pass that lets him ride trains without limit for a month. The pass does not cover bus fares, however.

Marijonas will stay in exactly one city, but he has not decided which one yet. Since he plans to visit many cities during his stay, he wants to choose a city from which he can travel cheaply to every other city.

For Marijonas, traveling from one city to another is cheap if there is a route that uses any number of trains and at most one bus.

Count the number of cities Marijonas could stay in — that is, the cities from which he can travel cheaply to all other cities.

Input

The first line contains two integers: the number of cities NN and the number of connections MM. Cities are numbered from 11 to NN.

Each of the next MM lines contains two integers aia_i and bib_i and a character TiT_i. The ii-th connection joins cities aia_i and bib_i. The character TiT_i gives the type of transport: if TiT_i is T the connection is a train line, and if TiT_i is A it is a bus line.

Output

Print a single integer — the number of cities Marijonas could stay in.

Constraints

  • 1N5000001 \le N \le 500\,000
  • 0M5000000 \le M \le 500\,000