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 scanner = new Scanner(System.in); int stepsNumber = scanner.nextInt(); char[] steps = scanner.next().toCharArray(); int level = 0; boolean valley = false; int valleyNumbers = 0; for (char c : steps) { if(c == 'U') level++; else level--; if(level < 0 && valley == false) { valley = true; valleyNumbers++; } if(level >= 0) valley = false; } System.out.println(valleyNumbers); } }