# Enter your code here. Read input from STDIN. Print output to STDOUT num = gets step_lst = gets.strip().scan /\w/ val_count = 0 posY = 0 posY_arr = [0]; step_lst.each do |s| if s == 'U' posY += 1 else posY -= 1 end posY_arr.push(posY) end i = 1 while i <= posY_arr.length-1 do c_point = posY_arr[i] if c_point == 0 && posY_arr[i-1] < 0 val_count += 1 end i += 1 end puts val_count