# Enter your code here. Read input from STDIN. Print output to STDOUT n=int(raw_input().strip()) walk=raw_input().strip() alt=0 valley=False count=0 for i in xrange(n): if walk[i]=='U': alt=alt+1 else: alt=alt-1 if alt<0: valley=True continue if alt==0 and valley: count=count+1 else: valley=False print count