#!/bin/python3 import sys n = int(input().strip()) steps = input().strip() valleys = 0 height = 0 lastheight = 0 for step in steps: if (step == 'U'): height += 1 else: height -=1 if (height == -1 and lastheight == 0): valleys += 1 lastheight = height print (valleys)