n=int(input()) l=input() steps=[];count=0;valley=0 steps.append(0) for i in range(len(l)): if(l[i]=="U"): count=count+1 steps.append(count) else: count=count-1 steps.append(count) for j in range(n): if((steps[j]==0)and(steps[j+1]==-1)): valley=valley+1 print(valley)