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