#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int n;
    cin>>n;
    int step_count=0;
    int count_valley=0;
    int prev_step = step_count;
    char arr[n];
    for(int i=0;i<n;i++)
        {
        cin>>arr[i];
        
        if(arr[i] == 'U') step_count++;
        else step_count--;
        
        if((prev_step<0) & (step_count==0)) count_valley++;
        prev_step = step_count;
    }
    cout<<count_valley;
    return 0;
}