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 in = new Scanner(System.in); int n = in.nextInt(); if(isValidValue(n)) { String steps = in.next(); System.out.println(getNumberOfValleys(steps)); } } private static int getNumberOfValleys(String steps) { if(isValidValue(steps.length())) { int seaLevel = 0; int valleys = 0; boolean isValleyIn = false; boolean isValleyOut = false; for(int i = 0; i < steps.length(); i++) { char step = steps.charAt(i); if(step == 'U') { seaLevel++; } else if(step == 'D') { seaLevel--; } if(seaLevel < 0) { isValleyIn = true; isValleyOut = false; } else if(seaLevel >= 0 && isValleyIn) { isValleyIn = false; isValleyOut = true; } else if(seaLevel >= 0 && !isValleyIn) { isValleyIn = false; isValleyOut = false; } if(isValleyOut) { valleys++; } } return valleys; } else { return 0; } } private static boolean isValidValue(int i) { return i >= 2 && 1 <= 1000000; } }