n = int(raw_input().strip()) step = raw_input().strip() level=0 flag=1 status='s' count=0 for x in step: if x=='U': level+=1 if x=='D': level-=1 if status=='s' and level<0 : status='v' elif status=='s' and level>0 : status='m' elif status =='v' and level==0: status='s' count+=1 elif status == 'm' and level==0: status='s' print count