#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592654;
bool check(long long sum, long long n) { return sum * 10 >= n * 45; }
int main(void) {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  long long tc, l, k = 0, sum = 0, x = 0, y = 0, z = 0, m = 1, n = 0, ans = 0,
                   cnt = 0;
  cin >> n;
  string s;
  cin >> s;
  for (long long i = 0; i < n - 1; i++) {
    if (s[i] == 'U')
      y++;
    else
      x++;
    if (x == y && s[i] == s[i + 1]) ans++;
  }
  cout << ans;
}
