Farmer John decides to build a new fence around parts of his farm, but he keeps getting distracted and ends up building the fence in a much stranger shape than he originally intended!
Specifically, FJ starts at position and takes steps, each moving one unit of distance north, south, east, or west. With each step, he lays a unit-length segment of fence behind him. For example, if his first step is north, he adds a segment of fence from to . FJ may revisit points multiple times, and he may even lay the same segment of fence multiple times. His fence may also cross itself if his path passes through a segment of fencing that he has already built.
Needless to say, FJ is rather dismayed by the result after completing the fence. In particular, he notices that he may have partitioned some areas of the farm from others, so that one can no longer walk from one region to another without crossing a fence. FJ would like to add gates to his fences to fix this problem. A gate can be added to any unit-length segment of fence he has built, allowing passage between the two sides of that segment.
Please determine the minimum number of gates FJ needs to add so that every region of the farm is once again reachable from every other region.
The first line contains an integer n~(1 \le n \le 1000). The next line contains a string of length describing FJ's path. Each character is either (north), (east), (south), or (west).
Print a single integer giving the minimum number of gates FJ needs to add to restore complete connectivity among all regions of his farm. Note that the answer may be zero if the farm is connected to begin with.
Beispiel 1