#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int in = (s[0] == 'U') ? 1 : -1;
  int flag = (in == 1) ? 0 : 1;
  for (int i = 1; i < n; i++) {
    in += (s[i] == 'U') ? 1 : -1;
    if (in == 0) continue;
    if (in > 0 && flag == 1) {
      flag = 0;
      ans++;
    }
    if (in < 0 && flag == 0) {
      flag = 1;
      ans++;
    }
  }
  cout << ans;
}
