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