import sys n = n = int(input().strip()) walk = list(str(input())) current = 0 num_valleys = 0 is_valley = False for step in walk: # if we're going up if step == 'U': if is_valley: # if we are just coming out of a valley mark that we have another valley if current == -1: num_valleys += 1 is_valley = False current += 1 # if we're going down and we were at sea level, mark that we're now in a valley elif step == 'D': if current == 0: is_valley = True current -= 1 print(num_valleys)