public boolean isGoal() {
        for (int i = 0; i < N2 - 1; i++) {
            if (tiles[i] != i + 1)
                return false;
        }
        if (tiles[N2 - 1] != 0) {
            return false;
        }
        return true;
    }