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