n = int(input()) path = input() seaLevel = 0 prevHeight = 0 height = 0 i = 0 numValleys = 0 while(i < n): prevHeight = height if(path[i] == "U"): height +=1 else: height -= 1 if(height == seaLevel and prevHeight == -1): numValleys += 1 i+= 1 print(numValleys)