# Enter your code here. Read input from STDIN. Print output to STDOUT import sys n = int(raw_input().strip()) steps = raw_input() level = 0 last_level = 0 valleys = 0 in_valley = False for step in steps: level = level + 1 if step == "U" else level - 1 if level < 0: if in_valley == False: valleys = valleys + 1 in_valley = True if level >= 0: in_valley = False print valleys