
"use strict";

process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {

    const n = parseInt(input[0], 10);

    let a = new Array(n);
    for (let i = 0; i < n; i++) {
        a[i] = input[i + 1];
    }

    let ans = 0;
    let topB = 0;
    let bottomA = 0;
    let ab = 0;
    for (let i = 0; i < n; i++) {
        let offset = 0;
        while (offset < a[i].length) {
            offset = a[i].indexOf('AB', offset);
            if (offset < 0) {
                break;
            }
            ans++;
        }
        if (a[i].substr(0, 1) === 'B') {
            topB++;
        }
        if (a[i].substr(-1, 0) === 'A') {
            bottomA++;
        }
        if (a[i].substr(0, 1) === 'B' && a[i].substr(-1, 0) === 'A') {
            ab++;
        }
    }

    if (topB === bottomA && topB === ab) {
        ans += ab - 1;
    } else {
        ans += Math.min(topB, bottomA);
    }

    console.log(ans);

    return 0;
}