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) { Scanner in = new Scanner(System.in); int n = in.nextInt(); char[] path = in.next().toCharArray(); int level = 0; int prevLevel = 0; int numberOfValleys = 0; for (int i = 0; i < n; i++) { char nextStep = path[i]; if (nextStep == 'U') { level++; } else { level--; } if (prevLevel == 0) { if (level < 0) { numberOfValleys++; } } prevLevel = level; } System.out.println(numberOfValleys); } }