#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
char _;
inline long long powmod(long long x, long long n, long long _mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * x) % _mod;
    x = (x * x) % _mod;
    n >>= 1;
  }
  return res;
}
int n;
string s;
int xx[200005], yy[200005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  cin >> s;
  if (int((s).size()) < 3) {
    cout << 0 << '\n';
    return 0;
  }
  int ans = 0;
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'U') {
      y++;
    } else {
      x++;
    }
    xx[i + 1] = x;
    yy[i + 1] = y;
  }
  for (int i = 2; i <= n; i++) {
    if (xx[i - 1] == yy[i - 1]) {
      long long d = 1LL * (xx[i - 2] - yy[i - 2]) * (xx[i] - yy[i]);
      if (d < 0LL) {
        ans++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
