#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  cin >> n;
  string s;
  cin >> s;
  bool flag = true;
  pair<int, int> cur(0, 0);
  if (s[0] == 'U')
    cur.second++, flag = false;
  else
    cur.first++;
  int ans = 0;
  for (int i = 1; i < s.size(); ++i) {
    pair<int, int> tmp = cur;
    if (s[i] == 'U')
      tmp.second++;
    else
      tmp.first++;
    if (flag && tmp.second > tmp.first)
      ans++, flag = false;
    else if (!flag && tmp.first > tmp.second)
      ans++, flag = true;
    cur = tmp;
  }
  cout << ans << endl;
}
