import sys import re input = [] for line in sys.stdin: input.append(line) list = [] for l in input[1]: if l =='U': list.append(1) else: list.append(-1) v = 0 h = 0 for i in list: h_old = h h += i if h == 0 and h_old < 0: v += 1 print v