#include <bits/stdc++.h>
int main() {
  int n, cnt = -1;
  int x = 0, y = 0;
  char ch, stat = 0;
  scanf("%d", &n);
  while (n--) {
    scanf(" %c", &ch);
    if (ch == 'U')
      y++;
    else
      x++;
    if (x < y) {
      if (stat != 1) cnt++;
      stat = 1;
    } else if (x > y) {
      if (stat != 2) cnt++;
      stat = 2;
    }
  }
  printf("%d", cnt);
  return 0;
}
