#include <bits/stdc++.h>
using namespace std;
int n, first[100005], second[100005], ans = 0;
void solve() {
  string s;
  cin >> n >> s;
  for (int i = 1; i < n + 1; i++) {
    first[i] = first[i - 1];
    second[i] = second[i - 1];
    if (s[i - 1] == 'U')
      second[i]++;
    else
      first[i]++;
  }
  for (int i = 1; i < n; i++) {
    if (first[i] == second[i] &&
        (first[i - 1] == first[i + 1] || second[i - 1] == second[i + 1]))
      ans++;
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
