steps = input() updown = list(raw_input()) height = [0] valleys = 0 in_valley = False for x in updown: if x == "U": height.append(height[-1] + 1) if x == "D": height.append(height[-1] - 1) for h in range(0,steps+1): if in_valley == False and int(height[h]) < 0: in_valley = True if in_valley == True and int(height[h]) == 0: valleys +=1 in_valley = False print valleys