#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int MAX = 3e5;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
int main() {
  ios::sync_with_stdio(false);
  long long n, i, x = 0, y = 0, curr, ans = 0;
  string s;
  cin >> n >> s;
  curr = ((s[0] == 'U') ? 1 : 0);
  for ((i) = 0; (i) < (s.size()); ++(i)) {
    if (s[i] == 'U')
      y++;
    else
      x++;
    if (x < y && curr != 1) {
      ans++;
      curr = 1;
    } else if (x > y && curr != 0) {
      ans++;
      curr = 0;
    }
  }
  cout << ans;
}
