# Enter your code here. Read input from STDIN. Print output to STDOUT

level=0
n=int(raw_input().strip())
s=raw_input().strip()
count=0

for i in s:
    if i=='U':
        level+=1
    else:
        level-=1
    if i=='U' and level==0:
        count+=1
print count