#include <bits/stdc++.h>
using namespace std;
int N = 1e6;
long long S = 1e9 + 7;
int ans = 0;
int main() {
  int n;
  scanf("%d ", &n);
  int x = 0, y = 0;
  string k;
  cin >> k;
  for (int(i) = (0); (i) < (n - 1); (i)++) {
    if (k[i] == 'U')
      y++;
    else
      x++;
    if (x == y) {
      if (k[i] == k[i + 1]) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
