# Read info numElements = int(input().strip()) steps = input() altitude = 0 numValleys = 0 valleyFlag = 0 # Algorithm for step in steps: if step == 'D': if altitude == 0: valleyFlag = 1 altitude = altitude - 1 elif step == 'U': if altitude == -1: valleyFlag = 0 numValleys = numValleys + 1 altitude = altitude + 1 print(int(numValleys))