#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int z = 0;
  int x = 0, y = 0;
  if (s[0] == 'U') {
    z = 1;
    y += 1;
  } else {
    z = 0;
    x += 1;
  }
  int c = 0;
  for (int i = 1; s[i] != '\0'; i++) {
    if (s[i] == 'U')
      y++;
    else
      x++;
    if (z == 1) {
      if (x > y) {
        c++;
        z = 0;
      }
    } else {
      if (y > x) {
        c++;
        z = 1;
      }
    }
  }
  cout << c;
}
