n=input() s=input() x=0 v=0 c=-1 for i in s: x=x+1 if i=='U' else x-1 if x<0: c=0 if c==0 and x==0: v+=1 c=-1 else: print(v)