/*
PROBLEM: C1
LANG: C
NAME: Svilen Marchev
SCHOOL: 12 SOU, Sofia
*/

#include <stdio.h>

#define MAXN		2010
#define NO_PARENT	-1

int prev[MAXN], s[MAXN];
int n;

int getRoot(int i)
{
	int root = i;
	while (prev[root] != NO_PARENT)
		root = prev[root];
	return root;
}

int checkTree()
{
	int i, r, r1;

	for (i = 1; i <= MAXN; i++) {
		if (prev[i] != NO_PARENT) {
			r = getRoot(i);
			break;
		}
	}

	for (i++; i <= MAXN; i++) {
		if (prev[i] != NO_PARENT) {
			r1 = getRoot(i);
			if (r1 != r)
				return NO_PARENT;
		}
	}

	return r;
}

int buildTree()
{
	int i, n1, n2, r1, r2;

	//freopen("1c1.in", "r", stdin);
	scanf("%d", &n);

	for (i = 0; i <= MAXN; i++) {
		prev[i] = NO_PARENT;
		s[i] = 1;
	}

	for (i = 0; i < n; i++) {
		scanf("%d %d", &n1, &n2);
		if (prev[n2] != NO_PARENT)
			return 0;
		r1 = getRoot(n1);
		r2 = getRoot(n2);
		prev[r2] = r1;
		s[r1] += s[r2];
	}

	return 1;
}

int main()
{
	int root;
	if (buildTree()) {
		root = checkTree();
		if (root == NO_PARENT)
			printf("0 0");
		else
			printf("%d %d", s[root], root);
	}
	else printf("0 0");

	return 0;
}