n = int(input()) seq = input() steps = 0 valleys = 0 in_valley = False for i in range(n): if seq[i] == "U": steps += 1 else: steps -= 1 if steps == 0 and seq[i] == "U": valleys += 1 print(valleys)