public static void main(String[] argv) throws Exception {
        int[] b = new int[10];
        b[1] = _int();
        b[2] = _int();
        b[3] = _int();
        int up = _int();
        b[4] = _int();
        b[5] = _int();
        b[6] = _int();
        int down = _int();
        b[7] = _int();
        b[8] = _int();
        b[9] = _int();
        int dbl = _int();
        b[0] = _int();

        int from = _int();
        int to = _int();

        Set<Integer> buttons = new HashSet<Integer>();
        for (int i = 0; i < 10; i++) {
            if (b[i] == 1) {
                buttons.add(i);
            }
        }

        producers.add(new SingleButtonStepProducer(buttons));
        if (dbl == 1) {
            producers.add(new DoubleButtonStepProducer(buttons));
        }
        if (up == 1) {
            producers.add(new UpStepProducer());
        }
        if (down == 1) {
            producers.add(new DownStepProducer());
        }

        ButtonStep fromButton = new ButtonStep(from, 0);
        steps.add(fromButton);
        while (steps.size() > 0) {
            ButtonStep current = steps.pollFirst();

            if (visited.contains(current.button)) {
                continue;
            }
            visited.add(current.button);
            
            if (current.button == to) {
                System.out.println(current.steps);
                return;
            }
            for (StepProducer p: producers) {
                p.produceSteps(current, steps);
            }
        }
        System.out.println(-1);
    }