# Enter your code here. Read input from STDIN. Print output to STDOUT step_count = gets.chomp.to_i steps = gets.chomp.split("") height = 0 valley_count = 0 steps.each do |step| if step == "U" height+=1 else height-=1 end if height==0 and step == "U" valley_count+=1 end end puts valley_count