The rule here is that you start with 0, and whenever you get to a number you have not seen before, the following term is a 0. But if the number k has appeared previously in the sequence, then you count the number of terms since the last appearance of k, and that number is the following term. In more detail:
Term 1: The first term is 0 by definition.
Term 2: Since we havent seen 0 before, the second term is 0.
Term 3: Since we have seen a 0 before, one step back, the third term is 1
Term 4: Since we havent seen a 1 before, the fourth term is 0
Term 5: Since we have seen a 0 before, two steps back, the fifth term is 2.
And so on.
As of this release of this R-package, how fast max(sequence) grows, and whether every number eventually appears, are open questions. The latest investigations and theorems related to this sequence can be found at https://oeis.org/A181391/