/* Boris Todorov Peltekov
   8e SMG
*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

short list[100][100];
short ima[100];
short used[100];
short n,num=0;
short maxvrah;
short MM[100];
short cycl[100];

void Findmax()
{
int i,j=0,k;
for (i=0;i<100;i++)
    if (MM[i] > j)
       {j = MM[i];
	k = i;
       }
maxvrah = k;
}

void DFS(short i, short par)
{
unsigned k;
used[i] = 1;
for (k=0;k<num;k++)
    {
    if ((list[i][ima[k]] == 1) && (used[ima[k]] != 1))
       {if ((ima[k] != par) && (par != i))
	   {
	   cycl[i] = 1;
	   return;
	   }
	if (ima[k] != par)
	   DFS(ima[k],i);
       }
       else return;
    }
}

int Compare(const void *a, const void *b)
{ return (*(short *)a - *(short *)b);}
void Dobavi(short q)
{
int i,b=0;
for(i=0;i<num;i++)
   if (ima[i] == q)
      b=1;
if ((num == 0) || (b == 0))
   ima[num++] = q;
}

void Init()
{
int i,a,b;
scanf("%d",&n);
for(i=0;i<n;i++)
   {scanf("%d %d",&a,&b);
    list[a][b] = 1;
    list[a][a] = list[b][b] = 2;
    Dobavi(a);Dobavi(b);
    MM[a] = MM[a] + 1;
   }
qsort(ima,num,sizeof(ima[0]),Compare);
}

void Solve()
{
int i,b=0;
for(i=0;i<num;i++)
   {
   DFS(ima[i],0);
   if (cycl[ima[i]] == 1)
      {
      printf("0 0\n");
      b=1;
      }
   }
if (b == 0)
   {Findmax();
    printf("%d %d\n",num,maxvrah);
   }
}

int main()
{
int o;
clrscr();
Init();
Solve();
getch();
return 0;
}