# Enter your code here. Read input from STDIN. Print output to STDOUT n = gets.to_i inp = gets f = false v = 0 x = 0 inp.each_char { |c| if c == "U" x += 1 else x -= 1 end if x < 0 f = true end if x == 0 and f f = false v += 1 end } puts v