import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int count = sc.nextInt(); String track = sc.next(); int level = 0; boolean inValley = false; int valleys = 0; for (int i = 0; i < count; i++) { char step = track.charAt(i); if (step == 'U') { level++; if (level == 0 && inValley) { valleys++; inValley = false; } } else if (step == 'D') { level--; if (level < 0 && !inValley) { inValley = true; } } } System.out.println(valleys); } }