num = int(raw_input()) stri = raw_input() i = 0 temp = 0 v = False numV = 0 while (i < num): temp = 0 if stri[i] == "U": temp = temp + 1 else: temp = temp - 1 i = i + 1 if i < num: while temp != 0: if stri[i] == "U": temp = temp + 1 v = True else: temp = temp - 1 v = False i = i + 1 if v == True: numV = numV + 1 print numV