# Enter your code here. Read input from STDIN. Print output to STDOUT n_steps = STDIN.readline.to_i() steps = STDIN.readline.chomp() features = [] level = 0 steps.each_char { |chr| if level == 0 features << 0 else features[-1] += level end level += (chr == "U" ? 1 : -1) } p features.count {|e| e < 0 }