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) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner in = new Scanner(System.in); int steps = in.nextInt(); in.nextLine(); String desc = in.nextLine(); int cState = 0, nState; int count = 0; char state = 's'; char c; for(int step = 0; step < steps; step ++){ c = desc.charAt(step); if(c == 'U'){ nState = 1; }else{ nState = -1; } cState += nState; if(cState <= -1){ state = 'd'; } else if(cState == 0 && state == 'd'){ count += 1; state = 's'; } } System.out.println(count); } }