n=int(raw_input()) top=raw_input().strip() lvl=0 count=0 for i in top: if i=="U":lvl+=1 else:lvl-=1 if i=="U" and lvl==0:count+=1 print count