// I. 678.
// Borsos Benedek, 9. osztály
// Debrecen, Debreceni Fazekas Mihály Gimnázium
// C++    Code::Blocks 20.03    wx3.1.3   gcc 8.1.0
#include<bits/stdc++.h>
using namespace std;
int meghivottak(string);
int N;
vector<string> V(0);

vector<string> lista(0);
bool meghivva(string);

main()
{
    ifstream be("cimlista.txt");

    for(string sor; getline(be, sor);)
    {
        V.push_back(sor);
    }
    N=V.size();
    string bemenet;
    getline(cin, bemenet);
    string aktualis="";

    int M=0;
    for(int i=0; i<bemenet.size(); i++)
    {
        aktualis="";
        while(i<bemenet.size() and bemenet[i]!=' ')
        {
             aktualis+=bemenet[i];
             i++;
        }
        M+=meghivottak(aktualis);
    }
    cout<<M<<endl;
    return 0;
}
int meghivottak(string email)
{
    if(meghivva(email)) return 0;
    else lista.push_back(email);

    string aktualis;
    int M=0;
    for(int i=0; i<N; i++)
    {
        aktualis="";
        int j=0;
        while(j<V[i].size() and V[i][j]!=' ')
        {
            aktualis+=V[i][j];
            j++;
        }

        if(aktualis==email)
        {
            if(j>=V[i].size())
            {

                return 1;
            }
            while(j<V[i].size())
            {
                j++;
                aktualis="";
                while(j<V[i].size() and V[i][j]!=' ')
                {
                    aktualis+=V[i][j];
                    j++;
                }
                M+=meghivottak(aktualis);
            }
            return M;
        }
    }

    return 1;
}
bool meghivva(string email)
{
    for(int i=0; i<lista.size(); i++)
    {
        if(email==lista[i]) return true;
    }
    return false;
}
