steps = int(input()) characters = input() level = 0 res = 0 for i in characters: if i == 'U': level+=1 elif i == 'D': level -= 1 if level == 0 and i == 'U': res += 1 print(res)