import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long T = scan.nextLong(); String seq = scan.next(); long numValleys = 0; boolean under = false; boolean over = false; long height = 0; for (int i = 0; i < T; i++){ if (seq.charAt(i) == 'U') height++; else height--; if (under && height == 0){ numValleys++; } if (height > 0) {over = true; under = false;} if (height < 0) {over = false; under = true;} if (height == 0) {over = false; under = false;} } System.out.println(numValleys); } }