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