num_valleys = 0 num_steps = int(raw_input().strip()) all_steps = raw_input() altitude = 0 for this_step_number in xrange(num_steps): this_step = all_steps[this_step_number] new_altitude = altitude + (1 if this_step == "U" else -1) if altitude == 0 and new_altitude < 0: num_valleys += 1 altitude = new_altitude print num_valleys