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 scan = new Scanner(System.in); int n = scan.nextInt(); String str = scan.next(); char[] arr = str.toCharArray(); boolean upFlag = false; boolean touchedSeaLevel = false; int count = 0; int totalCount = 0; int valleyCount = 0; for(char ch : arr){ if(count == 0 && ch == 'U'){ upFlag = true; }else if(count == 0 && ch=='D'){ upFlag = false; } if(ch == 'U'){ count++; totalCount++; } if(ch == 'D'){ count--; totalCount++; } if(totalCount>0 && count == 0){ touchedSeaLevel = true; } if(totalCount>0 && !upFlag && touchedSeaLevel){ valleyCount++; } touchedSeaLevel = false; } System.out.println(valleyCount); } }