import java.io.*; import java.util.*; class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public class Solution { public static void main(String[] args) { MyScanner input = new MyScanner(); int nrSteps = input.nextInt(); String steps = input.nextLine(); boolean underSea = false; int level = 0; int count = 0; for(int i = 0; i < steps.length(); i++){ if(steps.charAt(i) == 'U'){ level++; } else{ level --; } if(level == 0 && underSea == true) count ++; if(level >= 0) underSea = false; else underSea = true; } System.out.println(count); } }