public int smartSimulate(Map<Integer, Integer> orig2dest) {
		ArrayList<Integer> circlesLength = new ArrayList<Integer>();
		boolean[] visited = new boolean[orig2dest.size()];
		
		for(int i = 0; i < orig2dest.size(); i++) {
			if(!visited[i]) {
				int cur = i, count = 0;
				do{ // this do-while will find one circle
					visited[cur] = true;
					cur = orig2dest.get(cur);
					count++;
				} while(cur != i);
				circlesLength.add(count);
			}
		}
		
		if(circlesLength.size() == 1) return circlesLength.get(0);
		else {
			int num = circlesLength.get(0);
			// calculate the lease common multiply for all the lengths of circles
			for(int i = 1; i < circlesLength.size(); i++) {
				int gcd = gcd(num, circlesLength.get(i));
				int lcm = num * circlesLength.get(i) / gcd;
				num = lcm;
			}
			return num;
		}
	}