#include <iostream.h>
int matrix[2001][2001],n,i,l,j,a,b,vrt[2001],p=1,used[2001],queue[2001];
int br;
int max=2001;

int getroot(int kor)
{for (i=1;i<=max;i++)
 {if (matrix[i][kor]==1)
  {kor++;
   getroot(kor);
  }
 }
 for (i=1;i<=max;i++)
  {if (matrix[kor][i]==1) return kor;}
 if (kor < max) getroot(kor+1);
 else return 0;
 }

int check(int kor)
{for (i=1;i<=max;i++)
 {if (matrix[i][kor]==1)
  {br++;
   if (br==2) return 1;
  }
 }
 br=0;
 if (kor<max) {check(kor+1);}
 return 0;
}

int count (int masiv[2001])
 {int o=0;
  for (i=1;i<=2001;i++)
  {if (masiv[i]==1) o++;}
  return o;
 }

/*void dfs(int vertex)
{queue[p]=vertex;
 p++;
 used[vertex]=1;
 for (i=1;i<=max;i++)
  {if (matrix[vertex][i]==1 && used[i]!=1)
   dfs(i);
  }
}        */











int main()
{cin >> n;
 for (i=1;i<=n;i++)
  {cin >> a >> b;
   vrt[a]=1;vrt[b]=1;
   if (a > max) max=a;
   if (b > max) max=b;
   matrix[a][b]=1;
  }
 int brvert=count(vrt);
 int koren=getroot(1);
 if (koren == 0){cout << "0 0" ;return 0;}
 int tree=check (1);
 if (tree==1) {cout << "0 0" ;return 0;}
/* for (i=1;i<=max;i++)
  cout << queue[i] << " "; */
  cout << brvert << " " << koren;

 return 0;
}
