# Enter your code here. Read input from STDIN. Print output to STDOUT n=int(raw_input()) tt=map(lambda x: x.split(),raw_input()) step=0 acc=[] for t in tt: if t==['U']: step+=1 acc.append(step) else: step-=1 acc.append(step) ct=0 for j in range(len(acc)-1): if acc[j]==-1 and acc[j+1]==0: ct+=1 print ct