using System; using System.Linq; class Solution { static void Main(String[] args) { Console.ReadLine(); var values = Console.ReadLine().Select(z => z == 'U' ? 1 : -1); var sum = 0; var result = 0; var isGoToValley = false; foreach (var value in values) { if (sum == 0 && value == -1) { isGoToValley = true; } sum += value; if (sum == 0) { if (isGoToValley) { result++; isGoToValley = false; } } } Console.WriteLine(result); } }