# Enter your code here. Read input from STDIN. Print output to STDOUT n = raw_input() steps = raw_input() curlel = 0 prelel = 0 countvalley = 0 for i in range(len(steps)): if steps[i] == 'U': step = 1 elif steps[i] == 'D': step = -1 curlel += step if curlel < 0 and prelel >= 0: countvalley += 1 prelel += step print countvalley