steps=int(input()) walk=str(input().strip()) #print(walk) track=0 change=0 level=0 val=0 for i in walk: if i=="U": if track<0: level=-1 elif track>0: level=1 else: level=0 track= track+1 if track==0: change+=1 if i=="D": if track<0: level=-1 elif track>0: level=1 else: level=0 track= track-1 if track==0: change=1 else: change=0 if change==1 and level== -1: val= val+1 print(val)