// By J.D. Sandifer - 2016-07-26 import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); in.nextInt(); // Don't need n with this algorithm... String directions = in.next(); in.close(); int level = 0; int valleys = 0; for(char step : directions.toCharArray()) { switch (step) { case 'U': if (level == -1) { valleys++; } level++; break; case 'D': level--; break; } } System.out.println(valleys); } }