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