# Enter your code here. Read input from STDIN. Print output to STDOUT N=input() S=raw_input() count=0 sea_level=0 temp=0 for i in range(0, len(S)-1): if S[i]=='U': sea_level=sea_level+1 else: sea_level=sea_level-1 if sea_level<0 and temp==0: temp=1 count=count+1 if sea_level==0 and temp==1: #count=count+1 temp=0 print count