n=int(input()) arr=[x for x in input()] c=0 x=0 flag=0 for i in range(n): if(arr[i]=='U'): c=c+1 else: c=c-1 if(c<0 and flag==0): flag=1 x=x+1 elif(c>=0): flag=0 print(x)