n = int(input())
a = input()

direction = 0
height = 0
mountains = 0
valleys = 0

for s in a:
    if direction == 0:
        direction = 1 if s == "U" else -1
    height += 1 if s == "U" else -1
    if height == 0:
        if direction == -1:
            valleys += 1 
        direction = 0
print(valleys)