#include <bits/stdc++.h>
using namespace std;
int main() {
  char c;
  int a, ans = 0;
  int x = 0;
  int y = 0;
  int n, k, k1 = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c;
    if (c == 'U')
      y++;
    else
      x++;
    if (x > y)
      k = 1;
    else if (x < y)
      k = 2;
    if (x == y)
      continue;
    else {
      if (k1 != k) ans++;
      k1 = k;
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
