#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1e5 + 4;
const long long MOD = 1e12 + 7;
const long double pi = 3.141592653589793238462643383;
const int IMAX = 2e9;
template <class T>
using max_pq = priority_queue<T>;
template <class T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
long long x, y;
template <class T>
T gcd(T a, T b) {
  if (a == 0) {
    x = 0, y = 1;
    return b;
  }
  T gc = gcd(b % a, a);
  T temp;
  temp = x;
  x = y - (b / a) * temp;
  y = temp;
  return gc;
}
long long po(long long a, long long x, long long m) {
  if (x == 0) {
    return 1;
  }
  long long ans = 1;
  long long k = 1;
  while (k <= x) {
    if (x & k) {
      ans = ((ans * a) % m);
    }
    k <<= 1;
    a *= a;
    a %= m;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string second;
  cin >> second;
  int x = 0, y = 0;
  int pr;
  if (second[0] == 'U') {
    pr = 1;
    y++;
  } else {
    pr = 0;
    x++;
  }
  int cn = 0;
  for (int i = int(1); i <= int(n - 1); i++) {
    if (second[i] == 'U')
      y++;
    else
      x++;
    if (x > y && pr == 1) {
      cn++;
      pr = 0;
    } else if (x < y && pr == 0) {
      cn++;
      pr = 1;
    }
  }
  cout << cn;
}
