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(); String s = in.next(); int level = 0; int count = 0; boolean hasValley = false; for (int i = 0; i < s.length(); i++) { if ('U' == s.charAt(i)) level++; else { if ('D' == s.charAt(i)) level--; } if ((level < 0) && (!hasValley)) hasValley = true; else { if ((level == 0) && (hasValley)) { count++; hasValley = false; } } } System.out.println(count); } }