import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; 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 in = new Scanner(System.in); int n = Integer.parseInt(in.nextLine()); String str = in.nextLine(); String[] arr = str.split(""); int sum = 0; ArrayList list = new ArrayList<>(); for(int i = 1; i <= n; i++) { if("U".equals(arr[i])) sum = sum +1; else sum = sum -1; //System.out.println(sum); list.add(sum); } list.add(0, 0); int count = 0; for(int k = 1; k < list.size(); k++) { if(list.get(k) == 0 && list.get(k-1) < 0) count++; } System.out.println(count); } }