import java.io.*; import java.util.*; 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 scanner = new Scanner(System.in); boolean valley = false; int valleys = 0; int ups = 0; int downs = 0; int steps = scanner.nextInt(); String ud = scanner.next(); for (int i = 0; i < steps; i++) { if (ups == 0 && downs == 0) { if (ud.substring(i, i + 1).equals("U")) { valley = false; ups++; } else { valley = true; downs++; } } else if (ud.substring(i, i + 1).equals("U")) { ups++; } else { downs++; } if (ups == downs) { if (valley) { valleys++; } ups = 0; downs = 0; } } System.out.println(valleys); } }