let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let ar = Array.make n "" in
  for i = 0 to n - 1 do
    Scanf.scanf "%s\n" (fun s -> ar.(i) <- s)
  done;
  let abs = ref 0 in
  let lasta = ref 0 in
  let firstb = ref 0 in
  for i = 0 to n - 1 do
    let l = String.length ar.(i) in
    for j = 0 to l - 1 do
      let c = String.get ar.(i) j in
      if j = 0 && c = 'B' then firstb := !firstb + 1;
      if j = l - 1 && c = 'A' then lasta := !lasta + 1;
      if j < (l - 1) then
        if String.sub ar.(i) j 2 = "AB" then abs := !abs + 1;
    done;
  done;
(*  Printf.printf "abs: %d, a: %d, b: %d\n" !abs !lasta !firstb;*)
  !abs + (min !lasta !firstb)
  |> print_int
