public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		int times = 0;
		int[] ids = new int[100001];
		while ((line = in.readLine()) != null) {
			if (times++ != 0)
				line = in.readLine();
			for (int i = 0; i < ids.length; i++)
				ids[i] = -1;
			int refused = 0, id = 0;
			ArrayList<Point> pairs = new ArrayList<Point>();
			while (!line.equals("-1")) {
				int[] pair = readInts(line);
				if (ids[pair[0]] == -1) 
					ids[pair[0]] = id++;
				if (ids[pair[1]] == -1) 
					ids[pair[1]] = id++;
				pairs.add(new Point(ids[pair[0]], ids[pair[1]]));
				line = in.readLine();
			}
			UnionFind G = new UnionFind();
			G.init(id+1);
			for (int i = 0; i < pairs.size(); i++) {
				Point pair = pairs.get(i);
				if (G.sameComponent(pair.x, pair.y))
					refused++;
				else
					G.union(pair.x, pair.y);
			}
			out.append(refused + "\n");
		}
		System.out.print(out);
	}