#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
const int sqrtn = 300;
const int inf = 987654321;
const int sz = 1e5 + 5;
const int mod = 1e9 + 7;
int n, vis[sz];
string str;
int main() {
  scanf("%d", &n);
  cin >> str;
  int ret = 0, x = 0, y = 0, last = 0;
  if (str[0] == 'U') {
    y++;
    last = 1;
  } else
    x++, last = 0;
  for (int i = 1; i < n; i++) {
    if (str[i] == 'U')
      y++;
    else
      x++;
    if (vis[i - 1]) {
      if (y > x && last == 0) {
        ret++, last = 1;
      } else if (x > y && last == 1) {
        ret++, last = 0;
      }
    }
    if (y == x) vis[i] = 1;
  }
  printf("%d", ret);
}
