#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  int i;
  cin >> n;
  string s;
  cin >> s;
  int flag = 0;
  int x = 0, y = 0;
  if (s[0] == 'U') {
    y++;
    flag = 1;
  } else {
    x++;
    flag = 0;
  }
  int ans = 0, cur;
  for (i = 1; i < n; i++) {
    if (s[i] == 'U')
      y++;
    else
      x++;
    if (x < y) {
      if (flag == 0) {
        ans++;
        flag = 1;
      }
    } else if (y < x) {
      if (flag == 1) {
        ans++;
        flag = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
