#include <bits/stdc++.h>
using namespace std;
pair<int, int> v[112345];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; ++i) v[i].first = 0, v[i].second = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'U')
      v[i].first++;
    else
      v[i].second++;
    if (i != 0) {
      v[i].first += v[i - 1].first;
      v[i].second += v[i - 1].second;
    }
  }
  int ans = 0;
  for (int i = 2; i < s.size(); ++i) {
    if (v[i].first > v[i].second && v[i - 2].first < v[i - 2].second) {
      ++ans;
    }
    if (v[i].first < v[i].second && v[i - 2].first > v[i - 2].second) {
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}
