import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.IntStream; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int count = 0; int h = 0; for (char c : br.readLine().toCharArray()) { int prevH = h; h += c == 'U' ? 1 : -1; if (prevH == 0 && h < 0) { count++; } } System.out.println(count); } }