import sys n = int(input().strip()) steps = input().strip() valley_count = 0 elevation = 0 is_mountain = False is_valley = False for step in steps: if elevation == 0: if step == 'U': elevation += 1 is_mountain = True else: ## step == 'D' elevation -= 1 is_valley = True elif elevation > 0: if step == 'U': ## is_mountain = True elevation += 1 else: ## step == 'D' elevation -= 1 if elevation == 0: is_mountain = False else: ## elevation < 0 if step == 'U': elevation += 1 if elevation == 0: is_valley = False valley_count += 1 else: ## step == 'D' ## is_valley = True elevation -= 1 print(valley_count)