private int compute(String line1, String line2) {
        // setup
        int b = Integer.parseInt(line1.split("\\s")[0]);
        int n = Integer.parseInt(line1.split("\\s")[1]);

        String tokens[] = line2.split("\\s");
        int barberTimes[] = new int[tokens.length];
        for (int i=0; i<barberTimes.length; i++) {
            barberTimes[i] = Integer.parseInt(tokens[i]);
        }

        int lcm = getLcm(barberTimes);
        int servedInLcmTime = 0;
        for (int barberTime : barberTimes) {
            servedInLcmTime += lcm / barberTime;
        }

        int x = 1;
        while (servedInLcmTime * x < n) {
            x++;
        }

        int numberServed = servedInLcmTime * (x - 1);
        int minTime = getMin(barberTimes);
        int timeElapsedForBarbers[] = new int[barberTimes.length];
        while (numberServed < n) {
            for (int i = 0; i < barberTimes.length; i++) {
                if (timeElapsedForBarbers[i] == 0) {
                    numberServed ++;
                    if (numberServed == n) {
                        return i+1;
                    }
                } else if (timeElapsedForBarbers[i] == barberTimes[i]) {
                    timeElapsedForBarbers[i] = 0;
                    numberServed ++;
                    if (numberServed == n) {
                        return i+1;
                    }
                }
                timeElapsedForBarbers[i] += minTime;
            }
        }

        return -1;
    }