#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x = 0, y = 0, rj = 0;
  cin >> n;
  string s;
  cin >> s;
  bool ina = 0;
  if (s[0] == 'U') {
    ina = 1;
    y = 1;
  } else
    x = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == 'U')
      y++;
    else
      x++;
    if (ina && x > y) {
      rj++;
      ina = 0;
    } else if (!ina && x < y) {
      rj++;
      ina = 1;
    }
  }
  cout << rj;
}
