#include<iostream>
using namespace std;
struct boy{
int data=0,L=0,R=0;
}tre[105];
int N,x,B=0;
void zhong(int p){
if(tre[p].L>0)zhong(tre[p].L);
B++;
if(tre[p].data==x)cout<<B;
if(tre[p].R>0)zhong(tre[p].R);
}
int main(){
cin>>N>>x;
for(int i=1;i<=N;++i){
cin>>tre[i].data>>tre[i].L>>tre[i].R;
}
zhong(1);
return 0;
}