#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
string rev(string s) {
  long long m = s.size();
  string tmp = "";
  for (long long i = m - 1; i >= 0; i--) {
    tmp += s[i];
  }
  return tmp;
}
int main() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long x, y;
  x = 0;
  y = 0;
  long long xcor[n + 1], ycor[n + 1];
  xcor[0] = 0;
  ycor[0] = 0;
  long long cnt = 0;
  if (n == 1)
    cout << 0 << endl;
  else {
    if (s[0] == 'U')
      xcor[1] = 0, ycor[1] = 1;
    else
      xcor[1] = 1, ycor[1] = 0;
    for (long long i = 2; i <= n; i++) {
      if (s[i - 1] == 'U')
        xcor[i] = xcor[i - 1], ycor[i] = ycor[i - 1] + 1;
      else
        xcor[i] = xcor[i - 1] + 1, ycor[i] = ycor[i - 1];
      if ((xcor[i] - ycor[i]) * (xcor[i - 2] - ycor[i - 2]) < 0) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
