function processData(input) { // Define Variables var inputs = input.split("\n"), numSteps = Number(inputs[0]), steps = inputs[1].trim(), numValleys = 0, level = 0; // Iterate over the array for (var i = 0; i < numSteps; i++){ if(steps[i] == "U"){ level += 1; } else if(steps[i] == "D"){ level -= 1; if(level == -1) numValleys += 1; } } // Print answer console.log(numValleys); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });