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

namespace SIO
{
    class Program
    {
        struct Parovi
        {
            public int prvi;
            public int drugi;
            public string slovo;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Parovi[] parovi = new Parovi[n - 1];
            int br = 0, brS = 0, brI = 0, brO = 0;
            for (int i = 0; i < n - 1; i++)
            {
                string[] red = Console.ReadLine().Split();
                parovi[i].prvi = int.Parse(red[0]);
                parovi[i].drugi = int.Parse(red[1]);
                parovi[i].slovo = red[2];
                if ((parovi[i].prvi <= parovi[i].drugi) && (parovi[i].drugi <= n))
                {
                    br++;
                    if (parovi[i].slovo == "S") brS++;
                    else if (parovi[i].slovo == "I") brI++;
                    else brO++;
                }
            }
            if ((brS != brI) || (brS != brO) || (brI != brO)) br = Math.Min(Math.Min(brS, brI), brO);
            Console.WriteLine(br);
        }
    }
}