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