n = int(input()) steps = input().strip() pos = 0 valleys = 0 for c in steps: if c=='U': npos = pos + 1 else: npos = pos - 1 if (pos==-1) and (npos==0): valleys += 1 pos = npos print(valleys)