#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, x = 0, y = 0, r = 0, t;
  cin >> n;
  string s;
  cin >> s;
  t = s.size();
  vector<long long> a(t);
  vector<long long> b(t);
  if (n < 4) {
    cout << "0";
    return 0;
  }
  for (i = 0; i < s.size(); i++) {
    if (s[i] == 'U') {
      y++;
      a[i] = x;
      b[i] = y;
    } else {
      x++;
      a[i] = x;
      b[i] = y;
    }
  }
  for (i = 1; i < n - 1; i++) {
    if (a[i] == b[i]) {
      if ((a[i - 1] < a[i] && a[i] < a[i + 1]) ||
          (b[i - 1] < b[i]) && b[i] < b[i + 1])
        r++;
    }
  }
  cout << r;
  return 0;
}
