# Enter your code here. Read input from STDIN. Print output to STDOUT len = gets.strip.to_i arr = gets.strip.split('') valleys = 0 level = 0 down = false arr.each do |l| if l == 'U' level += 1 else level -= 1 end if level < 0 down = true end if level == 0 and down valleys += 1 down = false end end puts valleys