#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <ctime>

#define forr(a,b,c) for(int a = b; a < c; ++ a)
#define fore(a,b,c) for(int a = b; a <= c; ++ a)

#define pii pair<int,int>
#define int3 pair<pair<int,int>, int>
#define vi vector<int>
#define vs vector<string>

//#define DEBUG

using namespace std;

int main(){
	
	#ifndef DEBUG
		freopen("DATA5.txt", "r", stdin);
		freopen("OUT5.txt", "w", stdout);
	#endif
	
	forr(_r,0,5){
		bool graph[20][20];
		bool counts[20];
		
		bool onecol = true;
		
		memset(counts,0,sizeof(counts));
		memset(graph,0,sizeof(graph));
		
		int edges;
		cin >> edges;
		
		for(int i=0; i<edges; ++i){
			int a, b;
			cin >> a >> b; --a; --b;
			if(a==b){
				counts[a] = counts[b] = 1;
			}
			else{
				onecol = false;
				counts[a] = counts[b] = graph[a][b] = graph[b][a] = 1;
			}
		}
		
		if(onecol){
			cout << "1\n";
			continue;
		}
		
		bool twocol[20];
		bool col[20];
		
		for(int i=0; i<20; ++i) twocol[i] = col[i] = 0;
		
		bool out, bipart=true;
		
		for(int cc=0; cc<20; ++cc){
			if(twocol[cc] || !counts[cc]) continue;
			
			twocol[cc] = col[cc] = 1;
			
			do{
				out = true;
				for(int i=0; i<20; ++i){
					if(!counts[i]) continue;
					for(int j=i+1; j<20; ++j){
						if(!counts[j] || !graph[i][j]) continue;
						if(twocol[i] && twocol[j] && col[i]==col[j]){
						//	cout << i << '-' << j << ' ';
							bipart = false;
							break;
						}
						if(twocol[i] && !twocol[j]){
							col[j] = !col[i];
							twocol[j] = 1;
							out = false;
							break;
						}
					}
				}
			}while(!out);
		}
		
		if(bipart){
			cout << "2\n";
			continue;
		}
		
		bool c4=0, c5=0;
		
		forr(a,0,20){ if(!counts[a]) continue;
			forr(b,a+1,20){ if(!counts[b] || !graph[a][b]) continue;
				forr(c,b+1,20){ if(!counts[c] || !graph[a][c] || !graph[b][c]) continue;
					forr(d,c+1,20){ if(!counts[d] || !graph[a][d] || !graph[b][d] || !graph[c][d]) continue;
						c4 = true;
						forr(e,d+1,20){ if(!counts[2] || !graph[a][e] || !graph[b][e] || !graph[c][e] || !graph[d][e]) continue;
							c5 = true;
						}
					}
				}
			}
		}
		
		if(c5) cout << "0\n";
		else if(c4) cout << "4\n";
		else cout << "3\n";
	}
	
	#ifdef DEBUG
		system("pause");
	#endif
	
	return 0;
}

