input() path = input().strip() from itertools import groupby sub_path = groupby(path) h = 0 res = 0 for key, value in sub_path: h_old = h if key == 'U': h += len(list(value)) else: h -= len(list(value)) if h_old >= 0 and h < 0: res += 1 print(res)