# Enter your code here. Read input from STDIN. Print output to STDOUT n = raw_input().strip() s = raw_input().strip() valley = 0 level = 0 pass_sea = 1 begin_val = 0 for index, el in enumerate(s): if el == 'U': level += 1 else: level -= 1 if level < 0: begin_val = 1 if level == 0 and begin_val == 1: valley += 1 begin_val = 0 print valley