# Enter your code here. Read input from STDIN. Print output to STDOUT steps_count = raw_input() steps = list (raw_input()) current_level = 0 new_level = 0 valleys_count = 0 valley_began = True for step in steps: former_level = current_level if step == 'U': current_level = current_level + 1 else: current_level = current_level - 1 if (current_level < 0 and valley_began): valleys_count = valleys_count + 1 valley_began = False elif (current_level == 0 and former_level == -1): valley_began = True print valleys_count