#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cur = 0, sign = 0, ans = 0;
  for (auto c : s) {
    if (c == 'U')
      cur++;
    else
      cur--;
    if (sign == 1 && cur < 0)
      ans++;
    else if (sign == -1 && cur > 0)
      ans++;
    if (cur > 0)
      sign = 1;
    else if (cur < 0)
      sign = -1;
  }
  cout << ans << endl;
}
