# Enter your code here. Read input from STDIN. Print output to STDOUT N = int(raw_input().strip()) path = raw_input() level = 0 poss_valley = False valleys = 0 for step in path: if step == 'U': direction = 1 else: direction = -1 level += direction if poss_valley: if level == 0: valleys += 1 poss_valley = False else: if level == -1: poss_valley = True print valleys