import java.io.*;
import java.util.*;

public class gods_av_wa {

	FastScanner in;
	PrintWriter out;

	List<Integer>[] graph;

	boolean[] used;
	List<Integer>[] ans;
	
	void dfsLayout(int u, int c, int parent) {
		used[u] = true;
		ans[c].add(u);
		
		int nonLeaf = -1;
		for (int v : graph[u]) {
			if (v == parent) {
				continue;
			}
			if (used[v]) {
				throw new NoSolution();
			}
			
			if (graph[v].size() > 1) {
				if (nonLeaf >= 0) {
					throw new NoSolution();
				}
				nonLeaf = v;
			}
		}
		
		for (int v : graph[u]) {
			if (v == parent || v == nonLeaf) {
				continue;
			}
			ans[1 - c].add(v);
			used[v] = true;
		}
		if (nonLeaf >= 0) {
			dfsLayout(nonLeaf, 1 - c, u);
		}
	}

	void solve() {
		int n = in.nextInt();
		graph = new List[n];
		for (int i = 0; i < n; i++) {
			int k = in.nextInt();
			graph[i] = new ArrayList<>(k);
			for (int j = 0; j < k; j++) {
				graph[i].add(in.nextInt() - 1);
			}
		}
		
		ans = new List[2];
		ans[0] = new ArrayList<>();
		ans[1] = new ArrayList<>();
		used = new boolean[n];
		
		try {
			for (int i = 0; i < n; i++) {
				if (!used[i] && graph[i].size() <= 1) {
					dfsLayout(i, 0, -1);
				}
			}
			for (int i = 0; i < n; i++) {
				if (!used[i]) {
					throw new NoSolution();
				}
			}
		} catch (NoSolution e) {
			out.println(-1);
			return;
		}
		
		
		out.println(ans[0].size() + " " + ans[1].size());
		for (int i : ans[0]) {
			out.print((i + 1) + " ");
		}
		out.println();
		for (int j : ans[1]) {
			out.print((j + 1) + " ");
		}
		out.println();
	}

	class NoSolution extends RuntimeException {
	};

	void run() {
		try {
			in = new FastScanner("gods.in");
			out = new PrintWriter("gods.out");
			solve();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

	public static void main(String[] args) {
		new gods_av_wa().run();
	}
}
