# code template from sys import stdin def get(): return testcase.next().strip() testcase = stdin # solution starts here get() s = get() current = 0 count = 0 que = False for i in s: if i == "U": current += 1 if current == 0: if que: count += 1 que = False elif i == "D": current -= 1 if current == -1 and not que: que = True print count