In a kingdom ,number of rats (which can cause plague) have been let loose by an evil scientist to destroy the kingdom. The King has assigned the vital job of retrieving all of the rats to you. This is an ideal opportunity to test your latest invention, a rat trap which is guaranteed to retrieve every rat which walks into the cell containing the rat-trap.
Fortunately, you have the assistance of one of the world's foremost rat psychologists Shubham , who has the amazing ability of predicting, that if a rat is in a particular cell, exactly which of the four cardinal directions (north, east, south or west) the rat will head. While this information is handy, you still don't know where all the rats currently are.
In order to prove the cost-effectiveness of your method to the kingdom it would, of course, be important to minimize the number of traps used.
The kingdom will be an n x m grid of square subsections.
Input:- The input will begin with a line consisting of two numbers n and m, separated by a space . The next n lines will each consist of a string of length m, consisting of the letters 'N', 'E', 'S', or 'W', representing north, east, south and west, respectively. (The first character of the first line will be the northwesternmost point.) The letter in the cell indicates the direction in which rat will head if they are in that cell. Shubham assures you that rats have no interest in leaving the kingdom.
Output:- Minimum number of traps needed. 1 ≤ n, m ≤ 1000