function processData(input) { var s = input.split('\n')[1]; var h = 0; var cnt = 0; for (var i in s) { if (s[i] == 'U') { h++; } else { h--; if (h == -1) cnt++; } } console.log(cnt); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });