# Enter your code here. Read input from STDIN. Print output to STDOUT n = gets.strip.to_i topography = gets.strip.split('') valleys = 0 previous_height = 0 current_height = 0 topography.each do |step| if step == "U" current_height += 1 else current_height -= 1 end if previous_height == 0 && current_height == -1 valleys += 1 end previous_height = current_height end puts valleys