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[]) { int moveNum; Scanner in = new Scanner(System.in); moveNum = in.nextInt(); String moves = in.next(); int[] levels = new int[moveNum]; int last = 0; for(int i = 0; i < moveNum; i++) { if(moves.charAt(i) == 'U') { last++; levels[i] = last; } else { last--; levels[i] = last; } } int vallies = 0; boolean startValley = false; for(int i = 0; i < levels.length; i++) { if(levels[i] < 0) { startValley = true; } else if((levels[i] >= 0) && startValley) { vallies++; startValley = false; } } System.out.println(vallies); } }