# Enter your code here. Read input from STDIN. Print output to STDOUT n = gets.to_i steps = gets.strip.split('') current_level = 0 mountains = 0 valleys = 0 for i in 0..steps.size-1 previous = current_level if steps[i] == 'U' current_level += 1 else current_level -= 1 end if current_level == 0 if previous > 0 mountains += 1 end if previous < 0 valleys += 1 end end end puts valleys