#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,*s=open(0)\n"
"a=b=c=d=0\n"
"for t in s:\n"
"    if t[-2]=='A'and t[0]=='B':\n"
"        d+=1\n"
"    elif t[-2]=='A':\n"
"        a+=1\n"
"    elif t[0]=='B':\n"
"        b+=1\n"
"    c+=t.count('AB')\n"
"if all(i==0for i in(a,b)):\n"
"    print(c+max(0,d-1))\n"
"    exit()\n"
"elif a==b:\n"
"    print(a+c+d)\n"
"    exit()\n"
"ans=min(a,b)+c\n"
"dif=abs(a-b)\n"
"ans+=min(dif,d)\n"
"d-=min(dif,d)\n"
"print(ans+d)\n"
"\"";
  system(s);
  return 0;
}            