steps = gets.chomp.to_i step = gets.chomp count = 0 valley = 0 (1..step.length).each do |n| if step[n-1] == "U" count += 1 valley += 1 if count == 0 elsif step[n-1] == "D" count -= 1 else count += 0 end end puts valley