import sys s = int(input().strip()) steps = list(input().strip()) pos = 0 mc, vc = 0, 0 valley = False mountain = False for ss in steps: if ss == "U": pos += 1 elif ss == "D": pos -= 1 else: 0 if pos == 0: if mountain: mc += 1 elif valley: vc += 1 else: 0 if pos > 0: mountain = True valley = False elif pos < 0: valley = True mountain = False else: 0 # print(pos, mountain, valley) print(vc)