#include <iostream>
#include "testlib.h"

using namespace std;

int main()
{
    registerValidation();
    int n = inf.readInt(1, 100000, "n");
    inf.readSpace();
    int a[n+1], b[n+1];
    int k = inf.readInt(0, n-1, "k");
    inf.readEoln();
    for (int i = 1; i <= n; i++)
    {
        a[i] = inf.readInt(0, 1000000, "a[" + vtos(i) + "]");
        inf.readSpace();
        b[i] = inf.readInt(0, 1000000, "b[" + vtos(i) + "]");
        inf.readEoln();
    }

    inf.readEof();
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == 0 && b[i] != 0)
            quitf(_pe, "Error in format - zero time and non-zero reality (reality a[i] b[i]) %d %d %d",i,a[i],b[i]);
        if (a[i] != 0 && b[i] == 0)
            quitf(_pe, "Error in format - non-zero time and zero reality (reality a[i] b[i]) %d %d %d",i,a[i],b[i]);
        if (a[i] == 0)
        {
            cnt++;
        }
        if (b[i] <= b[a[i]] && a[i] != 0)
            quitf(_wa, "Time of reality is less then parent's %d > %d", b[i], b[a[i]]);
    }
    if (cnt == 0)
        quitf(_wa, "No start reality found");
    if (cnt > 1)
        quitf(_wa, "Many start realities found");
    return 0;
}
