function processData(input) { //Enter your code here var n = input.split("\n"); var steps = n[1]; n = parseInt(n[0], 10); var i = 0; var c = 0; var h = 0; for (; i < n; i++) { if (steps[i] === "D") { h--; if (h === -1) { c++; } } else { h++; } } console.log(c); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });