#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int dp[1001][2]; // assuming maximum number of nodes is 1000, can change it
vector< vector<int> >edges(1001);
/* Initialize dp[][] to be -1 for all values (u,select) */
/* Select is 0 or 1 for false/true respectively */
int func(int node , int select )
{
if(dp[node][select] != -1)return dp[node][select];
int ans = 0,i;
// value of node is node number itself
if(select)ans=node;
//edges[i] stores neighbors of node i
for(i=0;i<(int)edges[node].size();i++)
{
if(select)ans=ans+func(edges[node][i],1-select);
else ans=ans+max(func(edges[node][i],0),func(edges[node][i],1));
}
dp[node][select] = ans;
return ans;
}
// from main call, root is root of tree and answer is
// your final answer
int main()
{
memset(dp,-1,sizeof(dp));
int noofedges,root,i,parent,child;
//input takes number of edges and root of the tree in your test case 1
cin>> noofedges >> root;
for(i = 0;i < noofedges ;i++)
{
//then each edge is given as parent child
cin>> parent >> child;
edges[parent].push_back(child);
}
int answer = max(func(root,0),func(root,1));
cout<< answer <<endl;
// I have taken this kind of input format to make it easy you can change it, not much change will be there
}