#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0, y = 0, ans = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'U')
      ++y;
    else
      ++x;
    if (x == y && (i + 1 < n && s[i] == s[i + 1])) ++ans;
  }
  cout << ans << endl;
  return 0;
}
