#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, x = 0, y = 0, prex, prey, nexty, nextx, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] == 'U')
    y++;
  else
    x++;
  for (int i = 1; i < n - 1; ++i) {
    if (s[i] == 'U')
      y++;
    else
      x++;
    if (s[i] == 'U')
      prey = y - 1, prex = x;
    else
      prex = x - 1, prey = y;
    if (s[i + 1] == 'U')
      nexty = y + 1, nextx = x;
    else
      nexty = y, nextx = x + 1;
    if ((nexty - nextx) < 0 && (prey - prex) > 0 ||
        (nexty - nextx) > 0 && (prey - prex) < 0)
      ++ans;
  }
  cout << ans << "\n";
  return 0;
}
