num = input() string = input() list1 = list(string) def mon(num,list1): key = 0 count = 0 list2 = [0] new_list = [] list3 = [] for i in list1: if i == "D": key = key - 1 new_list += [key] if i == "U": key = key + 1 new_list += [key] for a in new_list: if a <= 0: list2 += [a] for b in range(len(list2) - 1): if list2[b] == 0 and list2[b+1] < 0: count += 1 return count print(mon(num,list1))