#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
    int n,i,x=0,y=0,ans=0;
    scanf("%d",&n);
    char str[n];
        scanf("%s",str);
        for(i=0;i<n;i++){
            if(str[i]=='U')
                x++;
            else
                x--;
            if(x<0 && y>=0){
                ans++;
                y=x;
            }
            if(x>=0)
                y=x;
                
        }
    printf("%d",ans);
    return 0;
}