function processData(input) { input = input.split("\n"); var n = input[0]; var arr = input[1]; var count = 0; var hike = 0; for (var i = 0; i < n; ++i) { (arr[i] == 'U')? hike++ : hike --; if (hike == 0 && arr[i] == 'U') count++; } console.log(count); } process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; }); process.stdin.on("end", function () { processData(_input); });