#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  char str[n + 2];
  cin >> str;
  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }
  int current = 0;
  int previous = 0;
  if (str[0] == 'U')
    current++;
  else
    current--;
  int count = 0;
  int sign = (current > 0 ? 1 : -1);
  for (int i = 1; i < n; i++) {
    previous = current;
    if (str[i] == 'U')
      current++;
    else
      current--;
    if (previous == 0 && sign != current) {
      count++;
      sign = current;
    }
  }
  cout << count << endl;
  return 0;
}
