import java.util.List; import java.util.Scanner; import java.util.stream.Collectors; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int steps = in.nextInt(); List path = in.next().chars().mapToObj(e -> (char) e) .collect(Collectors.toList()); int level = 0; int lastLevel; int valleys = 0; for (Character step : path) { lastLevel = level; if (step.equals('U')) { level++; } else { level--; } if (level == 0 && lastLevel < 0) { valleys++; } } System.out.println(valleys); } }