a = input() b = raw_input() count = 0 level = 0 flag = 0 for i in b: if i == "U": level += 1 else: level -= 1 if level < 0: flag = 1 if flag == 1 and level == 0: count += 1 flag = 0 print count