# Enter your code here. Read input from STDIN. Print output to STDOUT a = raw_input() steps = raw_input() count_v = 0 current_level = 0 below = False above = False for s in steps: if s == 'U': current_level += 1 else: current_level -= 1 if current_level < 0: below = True if current_level > 0: above = True if below and current_level== 0: count_v += 1 below = False print count_v