#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
long long state;
long long level=0;
long long v=0;
long long n;
string s;
vector <long long> t;
long long i;
int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    cin>>n;
    cin>>s;
    for(i=0;i<s.size();i++)
        {
            if(s[i]=='U')
                {
                level++;
            }
            else
            {
            level--;
            }
            if(level>0)
            {
            t.push_back(1);
            }
            else if(level==0)
            {
            t.push_back(0);
            }
            else
            {
                t.push_back(2);
            }
        
        }
   
     for(i=0;i<t.size()-1;i++)
        {
        if(t[i]==2 && t[i+1]==0)
            {
            v++;
        }
        
    }
    cout<<v;
    return 0;
}