const fi=''; fo=''; mn=100000;var a: array[0..mn] of char; n,dd,db: integer; f,g: text; i: integer; begin     dd:=0;     db:=0;     a[0]:='C';     assign(f,fi);reset(f);     assign(g,fo);rewrite(g);     readln(f,n);     for i:=1 to n do      begin       read(f,a[i]);       if a[i]<>a[i-1] then inc(dd);       if a[i]='B' then inc(db);      end;     if a[n]='A' then dec(dd);     if db<dd then dd:=db;     write(g,dd);     close(f);     close(g); end.