#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)(1e5 + 1e1);
const double PI = acos(-1.0);
int n, ans, x, y;
char a[MAXN];
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  v.push_back(make_pair(x, y));
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] == 'U')
      y++;
    else
      x++;
    v.push_back(make_pair(x, y));
  }
  for (int i = 0; i < v.size(); ++i) {
    if (v[i].first == v[i].second) {
      if (v[i + 1].first - v[i - 1].first == 2 ||
          v[i + 1].second - v[i - 1].second == 2)
        ans++;
    }
  }
  cout << ans;
  return 0;
}
