// number of elements var n = Int(readLine()!)! // read array var str = readLine()! var valleys = 0 var level = 0 for i in str.characters { if i == "U" { level += 1 } else if i == "D" { if level == 0 { valleys += 1 } level -= 1 } // print (level) } print(valleys)