```ts
function stepAllowed(from: string, to: string, allowed: string[][]): boolean {
  for (const move of allowed) {
    if (move[0] === from && move[1] === to) {
      return true;
    }
  }
  return false;
}

function stepPlan(states: string[], allowed: string[][]): number {
  for (let i = 0; i < states.length - 1; i++) {
    if (!stepAllowed(states[i], states[i + 1], allowed)) {
      return i;
    }
  }
  throw new Error('Run holding no states');
}
```