n = int(input()) steps = input() list = [] counter = 0 num_groups = 0 for s in steps: if s == 'U': counter+=1 else: counter-=1 if counter >=0: list.append('p') else: list.append('n') for i in range(len(list)-1): if list[i]=='n' and list[i+1]=='p': num_groups+=1 print(num_groups)