#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n;
char s[maxn + 1];
int main(void) {
  scanf("%d%s", &n, s);
  int x = 0, y = 0, side = -1, ans = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'U') {
      ++y;
    } else {
      ++x;
    }
    if (x > y) {
      if (side == 1) {
        ++ans;
      }
      side = 0;
    } else if (x < y) {
      if (side == 0) {
        ++ans;
      }
      side = 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
