import std.stdio, std.range, std.algorithm, std.conv, std.string, std.array, std.typecons, std.format;

void main() {
    long n;
    long bs = 0;
    long ae = 0;
    long bsae = 0;
    long cnt = 0;
    readf("%d\n", &n);
    foreach (_; 0..n) {
        auto s = readln.strip;
        cnt += s.count("AB");

        if(s[0] == 'B' && s[$-1] == 'A' ) {
            bsae = 1;
            bs++;
            ae++;
        } else if (s[0] == 'B') {
            bsae--;
            bs++;
        } else if (s[$-1] == 'A') {
            bsae--;
            ae++;
        }
    }


    if (bsae < 0) {
        bsae = 0;
    }

    writeln(cnt + min(bs, ae) - bsae);
}
