numSteps = int(raw_input().strip()) hikeSeq = raw_input().strip() previousHeight = 0 currentHeight = 0 numValleys = 0 for step in hikeSeq: if step == 'D': previousHeight = currentHeight currentHeight -= 1 if step == 'U': previousHeight = currentHeight currentHeight += 1 if currentHeight == 0: if previousHeight < 0: numValleys += 1 print numValleys