#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a = 0, b = 0, count = 0;
  char ch, c;
  cin >> n >> c;
  if (c == 'U')
    b++;
  else
    a++;
  n--;
  while (n--) {
    cin >> ch;
    if (a == b && ch != c) {
      count++;
      c = ch;
    }
    if (ch == 'U')
      b++;
    else
      a++;
  }
  cout << count;
}
