def valleys(steps): count = 0 valleys = 0 is_valley = False for step in steps: if step == 'U': count += 1 if count == 0 and is_valley: is_valley = False else: count -= 1 if count < 0 and not is_valley: valleys += 1 is_valley = True return valleys if __name__ == '__main__': walk = input() steps = list(raw_input()) print valleys(steps)