function processData(input) {
let string = input.split('\n');
let n = string[0];
let arr = string[1].split("");
let flag = 0 ;
let down = 0 ;
let res =0 ;
arr.forEach((a) =>{
if(a == 'U'){
flag++;
}else{
flag--;
}
if(flag < 0) down =1
if(flag ==0 && down == 1) res++, down = 0
} );
console.log(res)
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
_input += input;
});
process.stdin.on("end", function () {
processData(_input);
});