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

T diff(T)(const ref T a, const ref T b) { return a > b ? a - b : b - a; }

void main() {
    immutable n = readln.strip.to!(ulong);

    uint ab_cnt = 0;
    uint begin_B = 0;
    uint end_A = 0;
    for (ulong i = 0; i < n; i++) {
        immutable input = readln.strip;
        uint begin = 0;
        uint end = 0;

        bool afterA = false;
        foreach (c ; input) {
            switch (c) {
                case 'A' : afterA = true; break;
                case 'B' : if (afterA) ab_cnt++; goto default;
                default: afterA = false; break;
            }
        }
        if (input[0] == 'B') begin_B++;
        if (input[input.length - 1] == 'A') end_A++;
    }
    ab_cnt += min(begin_B, end_A);

    writeln(ab_cnt);
}
