#include <bits/stdc++.h>
using namespace std;
char s[100001];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  int res = 1e9;
  for (int it = 0; it < 2; ++it) {
    int last = it;
    int x = 0, y = 0;
    int cur = 0;
    for (int i = 0; i < n; ++i) {
      if (s[i] == 'U')
        ++y;
      else
        ++x;
      if ((y < x && last) || (y > x && !last)) {
        ++cur;
        last = !last;
      }
    }
    res = min(res, cur);
  }
  printf("%d\n", res);
  return 0;
}
