input() steps = input() valleys = 0 elevation = 0 was_below_sea_level = False for step in steps: elevation += (1 if step == 'U' else -1) if elevation < 0: was_below_sea_level = True elif elevation is 0 and was_below_sea_level: valleys += 1 was_below_sea_level = False print(valleys)