/*
Not sure if this is correct,
but there should be a solution along these lines
will explode if the array contains values outside of 1...n
also, invalidates the array
*/
int v = values[0];
for(;;){
if(v == values[v])return v;
int t = v;
v = values[v];
values[v] = t;
}