using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
//            Test();

            var N = ReadInt();
            var s = new string[N];
            for (int i = 0; i < N; i++) s[i] = ReadString();
            Out(Calc(s));
        }

        private static int Calc(string[] s)
        {
            int firstBCount = 0, lastACount = 0, firstBAndLastACount = 0, innerABCount = 0, nonEdgeCount = 0;
            for (int i = 0; i < s.Length; i++)
            {
                var str = s[i];
                if (str[0] == 'B' && str[str.Length - 1] == 'A')
                {
                    firstBAndLastACount++;
                    firstBCount++;
                    lastACount++;
                }
                else if (str[0] != 'B' && str[str.Length - 1] != 'A')
                {
                    nonEdgeCount++;
                }
                else
                {
                    if (str[0]              == 'B') firstBCount++;
                    if (str[str.Length - 1] == 'A') lastACount++;
                }

                for (int r = 0; r < str.Length - 1; r++)
                    if (str[r] == 'A' && str[r + 1] == 'B')
                        innerABCount++;
            }

            var edgeABCount = Math.Max(Math.Min(s.Length - nonEdgeCount - 1, Math.Min(firstBCount, lastACount)), 0);
            return edgeABCount + innerABCount;
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

    class PriorityQueue<T>
    {
    }
}

Measured memory_bytes: 13220