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 N = Integer.parseInt(in.nextLine()); String path = in.nextLine(); char[] pathChars = path.toCharArray(); int valleys = 0, seaLevel = 0; boolean isvalley = false; for(int i = 0; i < N; i++) { seaLevel = pathChars[i] == 'U' ? (seaLevel + 1) : (seaLevel - 1); if(seaLevel > 0) { isvalley = false; } else if(seaLevel < 0 ) { isvalley = true; } if(seaLevel == 0) { if(isvalley) valleys++; } } System.out.println(valleys); } }