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