#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cont = 0;
  scanf("%d", &n);
  int x = 0, y = 0, k;
  for (int i = 0; i < n; i++) {
    char c;
    scanf(" %c", &c);
    bool tr = false;
    if (c == 'U') {
      y++;
      if (i == 0)
        k = 2;
      else if (y > x && k == 1)
        tr = true, k = 2;
    } else {
      x++;
      if (i == 0)
        k = 1;
      else if (x > y && k == 2)
        tr = true, k = 1;
    }
    if (tr) cont++;
  }
  printf("%d\n", cont);
}
