c=0 z=0 a=int(input()) b=input() for i in b: if i == 'U': c+=1 else: c-=1 if c==0 and i=='U': z+=1 print(z)