object Solution { def main(args: Array[String]) { io.StdIn.readInt() var valleys = 0 var total = 0 for (i <- io.StdIn.readLine()) { if (i == 'U') { total = total + 1 } else if (i == 'D' && total == 0) { valleys = valleys + 1 total = total - 1 } else { total = total -1 } } println(valleys) } }