#include <stdio.h>
#define MAX_NODES 2002
struct node
{
	int length,empty,line;
};

int i,root_count=0,root,lines,out,in,node_count;
node nodes[MAX_NODES];

int main()
{
	for(i=0;i<MAX_NODES;i++)
	{
		nodes[i].empty=0;
		nodes[i].length=0;
		nodes[i].line=0;
	}
	scanf("%d",&lines);
	for(i=0;i<lines;i++)
	{
		scanf("%d %d",&out,&in);
		nodes[out].empty=1;	
		nodes[out].length++;
		nodes[in].empty=1;
		nodes[in].line++;
	}
	for(i=0;i<MAX_NODES;i++)
	{
		if(nodes[i].empty==0)continue;
		node_count++;
		if(nodes[i].line==0)
		{
			root_count++;
			root=i;
			if(root_count>1||nodes[i].length==0)
			{
				printf("0 0\n");
				return 0;
			}
		}
		if(nodes[i].line>1)
		{
			printf("0 0\n");
			return 0;
		}
	}
	printf("%d %d\n",node_count, root);
	return 0;
}