#include <bits/stdc++.h>
using namespace std;
int Scan() {
  int res = 0, flag = 0;
  char ch;
  if ((ch = getchar()) == '-') {
    flag = 1;
  } else if (ch >= '0' && ch <= '9') {
    res = ch - '0';
  }
  while ((ch = getchar()) >= '0' && ch <= '9') {
    res = res * 10 + (ch - '0');
  }
  return flag ? -res : res;
}
void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) {
    Out(a / 10);
  }
  putchar(a % 10 + '0');
}
int main() {
  int N;
  cin >> N;
  string str;
  cin >> str;
  double x = 1000000;
  double y = 1000000;
  int side = 0;
  int ans = 0;
  for (int i = 0; i < str.length(); i++) {
    if (str[i] == 'U') {
      y++;
      if (y / x > 1 && side == -1) {
        ans++;
        side = 1;
      } else {
        if (y / x < 1 && side == 1) {
          ans++;
          side = -1;
        }
      }
      if (y / x > 1)
        side = 1;
      else if (y / x < 1)
        side = -1;
    } else {
      x++;
      if (y / x > 1 && side == -1) {
        ans++;
        side = 1;
      } else {
        if (y / x < 1 && side == 1) {
          ans++;
          side = -1;
        }
      }
      if (y / x > 1)
        side = 1;
      else if (y / x < 1)
        side = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
