#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

bool linked[101][101];



    ifstream fin("DATA5.txt");
    ofstream fout("OUT5.txt");
bool longestPath(int from, int to) {
    int curLongest = -10000000;

    for (int i = 1; i <= 100; i++) {
        if (linked[from][i]) {
            if (i == to) curLongest = max(curLongest, 1);
            else curLongest = max(curLongest, longestPath(i, to) + 1);

            //cout << from << "->" << i << ": " << curLongest << endl;
        }
    }

    if (to == 1 && from == 1) fout << curLongest << endl;
    return curLongest;
}
int main() {

    int pathcount, n1, n2;
    for (int x = 0; x < 5; x++) {
        //cout << x << ": " << endl;
        for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) linked[i][j] = false;
        fin >> pathcount;
        for (int i = 0; i < pathcount; i++) {
            fin >> n1 >> n2;
            linked[n1][n2] = true;
        }

        int out = longestPath(1, 1);

        //cout << out << endl << endl;
    }
}

