# Enter your code here. Read input from STDIN. Print output to STDOUT import sys n = int(raw_input().strip()) walk = list(raw_input()) level = 0 prev_level = 0 valley_counter = 0 valley_flag = False for i,v in enumerate(walk): if v == "U": prev_level = level level +=1 #print "Step up" if v == "D": prev_level = level level -=1 #print "Step down" #print level if level == -1 and prev_level == 0: valley_counter += 1 #print "Valley detected" print valley_counter