step_map = {'U': 1, 'D': -1} def count_valleys(step_list): counts = {"mountains": 0, "valleys": 0} level = 0 status = "" for step in step_list: level += step_map[step] if step == 'D' and level < 0: # we're in a valley status = "valley" elif step == 'U' and status == "valley" and level == 0: counts["valleys"] += 1 status = "" return counts["valleys"] length = raw_input().strip() print(count_valleys(list(raw_input().strip())))