#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100001;
void precalc() {}
void clear() {}
void test() {}
void solve() {}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  precalc();
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0;
  int y = 0;
  int ans = 0;
  if (s[0] == 'U') {
    y = y + 1;
  } else {
    x = x + 1;
  }
  int st = 0;
  if (y > x) {
    st = 1;
  } else {
    if (x > y) {
      st = -1;
    }
  }
  for (int i = 1; i < n; i++) {
    if (s[i] == 'U') {
      y = y + 1;
    } else {
      x = x + 1;
    }
    int cur = 0;
    if (y > x) {
      cur = 1;
    } else {
      if (x > y) {
        cur = -1;
      }
    }
    if (st != cur && cur != 0) {
      ans++;
    }
    if (cur != 0) {
      st = cur;
    }
  }
  cout << ans << endl;
  int t = 0;
  while (t--) {
    solve();
  }
}
