Short Java Solution
```\nclass RLEIterator {\n        int a[], i;\n\n        public RLEIterator(int[] a) { this.a = a;}\n\n        public int next(int n) {\n            for (; i < 
```\nclass RLEIterator {\n        int a[], i;\n\n        public RLEIterator(int[] a) { this.a = a;}\n\n        public int next(int n) {\n            for (; i < a.length; i += 2)\n                if (n > a[i])\n                    n -= a[i];\n                else {\n                    a[i] -= n;\n                    return a[i + 1];\n                }\n            return -1;\n        }\n    }
[]