# Enter your code here. Read input from STDIN. Print output to STDOUT n=raw_input() s=raw_input() h=0 v=False res=0 for i in s: if i=='U': h+=1 else: h-=1 if h<0 and v==False: res+=1 v=True elif h>=0 and v==True: v=False print res