import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); String str = in.nextLine(); char[] steps = str.toCharArray(); boolean seaLevel = true; int stepDefiner = 0, counter = 0; for (int i = 0; i < steps.length; i++) { if (steps[i] == 'U') { stepDefiner++; } else { stepDefiner--; } if (stepDefiner == 0) { seaLevel = true; } else { seaLevel = false; } if (seaLevel) { if (steps[i] == 'U') { counter++; } } } System.out.println(counter); } }