import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); char[] step = scan.next().substring(0, n).toCharArray(); int sum = 0;//sea level == 0 int oldSum = 0;//when we going to first time minus - we in VALLEY int countValleys = 0; for(int i = 0; i < n; i++) { if(step[i] == 'U') sum += 1; else sum += -1; if(sum < 0 && oldSum >= 0) countValleys++; oldSum = sum; } System.out.println(countValleys); } }