Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.

At first, Arya and Bran have 0 Candies. There are n days, at the i-th day, Arya finds a_{i} candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of her candies. If she don't give him the candies at the same day, they are saved for her and she can give them to him later.

Your task is to find the minimum number of days Arya needs to give Bran k candies before the end of the n-th day. Formally, you need to output the minimum day index to the end of which k candies will be given out (the days are indexed from 1 to n).

Print -1 if she can't give him k candies during n given days.


-----Input-----

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000).

The second line contains n integers a_1, a_2, a_3, ..., a_{n} (1 ≤ a_{i} ≤ 100).


-----Output-----

If it is impossible for Arya to give Bran k candies within n days, print -1.

Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.


-----Examples-----
Input
2 3
1 2

Output
2
Input
3 17
10 10 10

Output
3
Input
1 9
10

Output
-1


-----Note-----

In the first sample, Arya can give Bran 3 candies in 2 days.

In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.

In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
(n, m) = map(int, input().split())
c = list(map(int, input().split()))
i = 0
l = 0
for i in range(n):
	l += c[i]
	m -= min(l, 8)
	l -= min(l, 8)
	if m <= 0:
		print(i + 1)
		break
else:
	print(-1)


def sol():
	import math
	(n, need) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	have = 0
	t = 0
	for i in range(n):
		have += arr[i]
		need -= min(8, have)
		have -= min(8, have)
		t += 1
		if need <= 0:
			print(t)
			return 0
	print(-1)
sol()


(n, k) = [int(x) for x in input().split()]
candies = [int(x) for x in input().split()]
has = 0
count = 0
while count < n:
	has += candies[count]
	if has < 8:
		k -= has
		has = 0
	elif has >= 8:
		k -= 8
		has -= 8
	count += 1
	if k <= 0:
		print(count)
		exit()
print(-1)


(n, k) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
if sum(a) < k or 8 * n < k:
	print(-1)
else:
	s = 0
	i = 0
	while s < k:
		s += a[i] if a[i] < 8 else 8
		i += 1
		if i == n:
			break
		a[i] += 0 if a[i - 1] < 8 else a[i - 1] - 8
	if s < k:
		print(-1)
	else:
		print(i)


(n, k) = map(int, input().strip().split())
a = []
a = list(map(int, input().strip().split()))
candies = 0
candinstr = 0
flag = 0
for i in range(n):
	if a[i] > 8:
		candies += 8
		candinstr = candinstr + a[i] - 8
	elif candinstr + a[i] > 8:
		candies += 8
		candinstr = candinstr + a[i] - 8
	else:
		candies += candinstr + a[i]
		candinstr = 0
	if candies >= k:
		flag = 1
		print(i + 1)
		break
if flag == 0:
	print('-1')


(n, k) = map(int, input().split())
list1 = list(map(int, input().split()))
ost = 0
count = 0
ans = 0
flag = False
for elem in list1:
	ost += elem
	ans += 1
	if count + min(ost, 8) >= k:
		flag = True
		break
	else:
		count += min(ost, 8)
		ost -= min(ost, 8)
if flag:
	print(ans)
else:
	print(-1)


from sys import stdin, stdout
(n, k) = map(int, stdin.readline().split())
values = list(map(int, stdin.readline().split()))
cnt = 0
sweet = 0
for i in range(n):
	cnt += values[i]
	v = min(min(cnt, 8), k - sweet)
	sweet += v
	cnt -= v
	if sweet == k:
		stdout.write(str(i + 1))
		break
else:
	stdout.write('-1')


(n, k) = map(int, input().split())
li = [int(x) for x in input().split()]
sav = 0
summ = 0
for i in range(n):
	can = sav + li[i]
	if can > 8:
		can = can - 8
		sav = can
		summ = summ + 8
	else:
		summ = summ + can
		sav = 0
	if summ >= k:
		print(i + 1)
		break
else:
	print(-1)


def main():
	(n, k) = (int(i) for i in input().split())
	a = [int(i) for i in input().split()]
	if min(sum(a), n * 8) < k:
		print(-1)
	else:
		total = 0
		count = 0
		residue = 0
		try:
			while total < k:
				residue += a[count]
				value = min(residue, 8)
				total += value
				residue -= value
				count += 1
			print(count)
		except:
			print(-1)
main()


(n, k) = map(int, input().split())
list = [int(i) for i in input().split()]
(cnt, i) = (0, 0)
while i < n and cnt < k:
	if i == n - 1:
		if list[i] > 8:
			cnt += 8
		else:
			cnt += list[i]
	elif list[i] > 8:
		cnt += 8
		list[i + 1] += list[i] - 8
	else:
		cnt += list[i]
	i += 1
if cnt < k:
	print('-1')
else:
	print(i)


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
s = 0
ans = 0
i = 0
for i in range(n):
	s += a[i]
	if s > 8:
		s -= 8
		ans += 8
	else:
		ans += s
		s = 0
	if ans >= k:
		break
if ans < k:
	ans = -1
else:
	ans = i + 1
print(ans)


R = lambda : map(int, input().split())
(n, k) = R()
arr = list(R())
last_reserve = 0
for i in range(n):
	last_reserve += arr[i]
	min_val = min(last_reserve, 8)
	last_reserve -= min_val
	k -= min_val
	if k <= 0:
		exit(print(i + 1))
print(-1)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
(n, k) = get_int_list()
lst = get_int_list()
a = b = 0
day = -1
for i in range(n):
	a += lst[i]
	m = min(8, a)
	a -= m
	b += m
	if b >= k:
		day = i + 1
		break
if day == -1:
	print(-1)
else:
	print(day)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = -1
ca = 0
cb = 0
for i in range(n):
	ca += a[i]
	c = min(ca, 8)
	ca -= c
	cb += c
	if k <= cb:
		ans = i + 1
		break
print(ans)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
x = 0
for i in range(n):
	x += a[i]
	if a[i] >= 8:
		k -= 8
		x -= 8
	elif x >= 8:
		k -= 8
		x -= 8
	else:
		k -= x
		x = 0
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(i + 1)


(n, k) = map(int, input().strip().split()[:2])
p = list(map(int, input().strip().split()[:n]))
z = False
count = 0
for x in range(len(p)):
	if p[x] <= 8:
		k -= p[x]
		count += 1
		if k <= 0:
			z = True
			break
	else:
		k -= 8
		if x != len(p) - 1:
			p[x + 1] += p[x] - 8
		count += 1
		if k <= 0:
			z = True
			break
if z == True:
	print(count)
else:
	print(-1)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
temp = 0
count = 0
i = 0
while temp < k and i < n:
	if a[i] < 8:
		temp = temp + a[i]
	else:
		temp = temp + 8
		if i + 1 < n:
			a[i + 1] = a[i + 1] + a[i] - 8
	count = count + 1
	i = i + 1
if temp >= k:
	if count <= n:
		print(count)
else:
	print(-1)


def main():
	(n, k) = [int(i) for i in input().split()]
	days = [int(i) for i in input().split()]
	arya = 0
	bran = 0
	dayCount = 0
	for day in days:
		arya += day
		transferrableCandies = min(arya, 8)
		arya -= transferrableCandies
		bran += transferrableCandies
		dayCount += 1
		if bran >= k:
			break
	if bran >= k:
		print(dayCount)
	else:
		print(-1)
main()


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
s = 0
o = 0
for x in range(n):
	if x != n - 1:
		if k > 0:
			if p[x] >= 8:
				k -= 8
				p[x + 1] += p[x] - 8
				s += 1
			else:
				k -= p[x]
				s += 1
		else:
			break
	elif k > 0:
		if p[x] >= 8:
			k -= 8
			s += 1
		else:
			k -= p[x]
			s += 1
	else:
		break
if k <= 0:
	print(s)
else:
	print(-1)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
(N, K) = map(int, input().split())
A = [int(x) for x in input().split()]
total = 0
for (i, v) in enumerate(A):
	total += v
	d = min(total, 8)
	total -= d
	K -= d
	if K <= 0:
		print(i + 1)
		exit(0)
print(-1)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
curr = 0
for i in range(n):
	curr += a[i]
	mn = min(curr, 8)
	curr -= mn
	k -= mn
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n - 1):
	a[i + 1] += a[i] - min(a[i], 8)
	a[i] = min(a[i], 8)
a[-1] = min(a[-1], 8)
ans = [i + 1 for i in range(n) if sum(a[:i + 1]) >= k]
print(ans[0] if ans else -1)


(n, k) = list(map(int, input().split()))
sweets = input().split()
i = 0
left = 0
count = len(sweets)
while k > 0:
	sweet = int(sweets[i])
	if sweet + left <= 8:
		k -= sweet + left
		left = 0
	else:
		k -= 8
		left += sweet - 8
	i += 1
	if i == count:
		break
if k > 0:
	print(-1)
else:
	print(i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
sav = 0
for i in range(n):
	s += min(a[i] + sav, 8)
	sav += a[i] - min(a[i] + sav, 8)
	if s >= k:
		print(i + 1)
		exit()
print(-1)


import sys
import inspect
import re
import math
from pprint import pprint as pp
mod = 998244353
MAX = 10 ** 15

def deb(p):
	for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
		m = re.search('\\bdeb\\s*\\(\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*\\)', line)
		print('%s %d' % (m.group(1), p))

def vector(size, val=0):
	vec = [val for i in range(size)]
	return vec

def matrix(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split())) + [0]
	i = 0
	while k > 0 and i < n:
		temp = min(a[i], 8)
		a[i + 1] += a[i] - temp
		k -= temp
		i += 1
	if k <= 0:
		print(i)
	else:
		print(-1)
main()


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
(a, res) = (0, 0)
for (i, x) in enumerate(lst):
	a += x
	k -= min(k, min(a, 8))
	a -= min(a, 8)
	if k == 0:
		res = i + 1
		break
if k > 0:
	print(-1)
else:
	print(res)


(a, b) = input().split()
a = int(a)
b = int(b)
li = list(map(int, input().split()))
i = 0
ans = 0
c = 0
extra = 0
test = 0
count = 0
while i < len(li):
	if int(li[i]) > 8:
		extra = extra + li[i] - 8
		add = 8
	elif extra != 0:
		c = 8 - li[i]
		if c <= extra:
			add = 8
			extra = extra - c
		else:
			add = li[i] + extra
			extra = 0
	else:
		add = li[i]
	ans = ans + add
	count = count + 1
	i = i + 1
	if b <= ans:
		test = 1
		i = len(li)
if test == 1:
	print(count)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
p = list(map(int, input().split()))
(a, b) = (0, 0)
for i in range(n):
	a += p[i]
	x = min(8, a)
	b += x
	a -= x
	if b >= k:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
day = 0
count = 0
for i in range(n):
	day += 1
	count += min(a[i], 8)
	if count >= k:
		print(day)
		break
	try:
		a[i + 1] += max(a[i] - 8, 0)
	except IndexError:
		pass
else:
	print(-1)


def arya_candles():
	total = input().split()
	days = input().split()
	posible_days = 0
	accumulated = 0
	saved = 0
	for i in range(len(days)):
		days[i] = int(days[i]) + saved
		saved = 0
		if int(days[i]) <= 8:
			posible_days += 1
			total[1] = int(total[1]) - int(days[i])
			if total[1] < 1:
				print(posible_days)
				return
		else:
			posible_days += 1
			total[1] = int(total[1]) - 8
			if total[1] < 1:
				print(posible_days)
				return
			saved = int(days[i]) - 8
	print(-1)
arya_candles()


(n, k) = map(int, input().split())
arr = input().split()
arr.append(0)
answer = 0
for i in range(n):
	arr[i] = int(arr[i])
for i in range(len(arr) - 1):
	if arr[i] < 8:
		k -= arr[i]
		arr[i] = 0
		answer += 1
		if k <= 0:
			break
	else:
		k -= 8
		arr[i + 1] += arr[i] - 8
		answer += 1
		if k <= 0:
			break
if k <= 0:
	print(answer)
else:
	print('-1')


(_, k) = [int(x) for x in input().strip().split(' ')]
size = [int(x) for x in input().strip().split(' ')]
candies = 0
bank = 0
for x in range(min(k, len(size))):
	togive = min(size[x], 8)
	if togive != size[x]:
		bank += size[x] - 8
	elif bank != 0:
		tmp = 8 - togive
		if bank >= tmp:
			togive = 8
			bank -= tmp
		else:
			togive += bank
			bank = 0
	candies += togive
	if candies >= k:
		print(x + 1)
		exit()
print(-1)


(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
a.append(0)
s = 0
i = 0
while s < k and i < n:
	if a[i] > 8:
		s += 8
		a[i + 1] += a[i] - 8
	else:
		s += a[i]
	i += 1
if s >= k:
	print(i)
else:
	print(-1)


import sys
import os
import math
import re
(n, k) = map(int, input().split())
c = list(map(int, input().split()))
totalDays = 0
t = 0
while k > 0 and totalDays < n:
	t += c[totalDays]
	if t > 8:
		k -= 8
		t -= 8
	else:
		k -= t
		t = 0
	totalDays += 1
if k > 0:
	print(-1)
else:
	print(totalDays)


(n, k) = map(int, input().split())
nums = list(map(int, input().split()))
i = 0
counter = 0
have = 0
left = 0
while counter < n and have < k:
	available = nums[counter] + left
	if available <= 8:
		have += available
		left = 0
	else:
		have += 8
		left = available - 8
	counter += 1
if have < k:
	print(-1)
else:
	print(counter)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cur = 0
res = 0
ans = -1
for i in range(n):
	if a[i] + cur <= 8:
		res = res + a[i] + cur
		cur = 0
	else:
		cur = a[i] - 8 + cur
		res += 8
	if res >= k:
		ans = i
		break
if ans == -1:
	print(-1)
else:
	print(ans + 1)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
total = 0
for i in range(n - 1):
	if A[i] > 8:
		(A[i], A[i + 1]) = (8, A[i + 1] + A[i] - 8)
	total += A[i]
	if total >= k:
		print(i + 1)
		break
else:
	print(-1 if total + min(A[-1], 8) < k else n)


(n, k) = map(int, input().split())
A = [int(x) for x in input().split()]
b = 0
c = 0
for i in range(n):
	b += A[i]
	c += min([b, 8])
	b = max([0, b - 8])
	if c >= k:
		print(i + 1)
		break
else:
	print(-1)


import math
import re
import os
import string
import sys

def ria():
	return [int(i) for i in input().split()]

def ri():
	return int(input())

def rfa():
	return [float(i) for i in input().split()]
eps = 1e-09

def is_equal(a, b):
	return abs(a - b) <= eps

def distance(p0, p1):
	return math.sqrt((p0[0] - p1[0]) ** 2 + (p0[1] - p1[1]) ** 2)
(n, k) = ria()
ar = ria()
cura = 0
suma = 0
for (n, i) in enumerate(ar):
	cur = min(i + cura, 8)
	cura -= cur
	cura += i
	suma += cur
	if suma >= k:
		print(n + 1)
		exit(0)
print(-1)


import math
import sys
import collections

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))
(n, k) = mi()
d = li()
a = b = 0
r = -1
for i in range(n):
	a += d[i]
	t = min(8, a)
	a -= t
	b += t
	if b >= k:
		r = i + 1
		break
print(r)


saved = 0
candies_at_present = 0
day_counter = 0
found = False
(days, wants_to_give) = map(int, input().split())
string = input()
for i in string.split():
	day_counter += 1
	todays_candies = int(i)
	if todays_candies >= 8:
		saved += todays_candies - 8
		candies_at_present += 8
		if candies_at_present >= wants_to_give:
			print(day_counter)
			found = True
			break
	else:
		needs_to_make_eight = 8 - todays_candies
		if saved <= needs_to_make_eight:
			candies_at_present += saved + todays_candies
			saved = 0
		else:
			saved -= needs_to_make_eight
			candies_at_present += 8
		if candies_at_present >= wants_to_give:
			print(day_counter)
			found = True
			break
if found is False:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
aria = 0
bran = 0
for i in range(n):
	aria += a[i]
	if aria > 8:
		bran += 8
		aria -= 8
	else:
		bran += aria
		aria = 0
	if bran >= k:
		print(i + 1)
		break
if bran < k:
	print(-1)


(n, k) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
a = 0
b = 0
d = 0
while b < k and d < n:
	a += s[d]
	tmp = min(8, a)
	a -= tmp
	b += tmp
	d += 1
if b >= k:
	print(d)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
(cnt, day) = (0, 0)
a = list(map(int, input().split()))
while k > 0:
	try:
		cnt += a[day]
	except IndexError:
		print(-1)
		return
	x = min(8, cnt)
	cnt -= x
	k -= x
	day += 1
print(day)


(n, k) = map(int, input().split())
v = 0
for (i, a) in enumerate(map(int, input().split())):
	v += a
	x = min(v, 8)
	v -= x
	k -= x
	if k <= 0:
		print(i + 1)
		exit()
print(-1)


f = list(map(int, input().split()))
(n, k) = (f[0], f[1])
a = list(map(int, input().split()))
c = 0
summ = 0
for e in range(n):
	summ += a[e]
	d = min(summ, 8)
	summ -= d
	k -= d
	if k <= 0:
		print(e + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
candy = 0
extra = 0
days = 0
for m in map(int, input().split()):
	days += 1
	m += extra
	x = min(8, m)
	candy += x
	extra = m - x
	if candy >= k:
		print(days)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
if n == 1 and k > 8 or (n == 1 and arr[0] < k):
	print(-1)
else:
	count = 0
	rem_candies = 0
	for i in range(0, len(arr)):
		if arr[i] < k:
			if arr[i] >= 8:
				count += 1
				k -= 8
				rem_candies += arr[i] - 8
			else:
				temp = arr[i] + rem_candies
				if temp >= 8:
					count += 1
					rem_candies = temp - 8
					k -= 8
					if k > 0:
						continue
					else:
						break
				else:
					count += 1
					rem_candies = 0
					k -= temp
					if k > 0:
						continue
					else:
						break
		elif arr[i] <= 8:
			count += 1
			k -= arr[i]
			break
		else:
			rem_candies += arr[i] - 8
			k -= 8
			count += 1
			if k > 0:
				continue
			else:
				break
	if k <= 0:
		print(count)
	else:
		print(-1)


(n, k) = map(int, input().split())
s = k
back = 0
arr = list(map(int, input().split()))
for i in range(n):
	num = arr[i]
	s -= min(8, num + back)
	back = max(0, back - 8 + num)
	if s <= 0:
		print(i + 1)
		exit(0)
print(-1)
exit(0)


(max_day, goal) = map(int, input().split())
gifts = map(int, input().split())

def candies():
	pocket = 0
	brann_pocket = 0
	for (day, gift) in enumerate(gifts, 1):
		pocket += gift
		brann_pocket += min(8, pocket)
		pocket -= min(8, pocket)
		if brann_pocket >= goal:
			print(day)
			return
	print(-1)
candies()


(n, k) = input().split()
n = int(n)
k = int(k)
a = input().split()
a.insert(0, 0)
tuiA = 0
tuiB = 0
dainchua = 0
for i in range(1, n + 1, 1):
	tuiA += int(a[i])
	if k - tuiB >= 8 and tuiA >= 8:
		tuiA -= 8
		tuiB += 8
	elif k - tuiB >= 8 and tuiA < 8:
		tuiB += tuiA
		tuiA = 0
	elif k - tuiB < 8 and tuiA >= k - tuiB:
		tuiB = k
	elif k - tuiB < 8 and tuiA < k - tuiB:
		tuiB += tuiA
		tuiA = 0
	if k - tuiB == 0:
		print(i)
		dainchua = 1
		break
if dainchua == 0:
	print(-1)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = 0
ost = 0
d = 0
flag = False
if n * 8 < k:
	print(-1)
else:
	for a in A:
		d += 1
		ost += a
		if ost > 8:
			ost -= 8
			s += 8
		else:
			s += ost
			ost = 0
		if s >= k:
			print(d)
			flag = True
			break
	if not flag:
		print(-1)


(n, k) = map(int, input().split())
a = map(int, input().split())
(tot, rest, d) = (0, 0, 0)
for x in a:
	d += 1
	rest += x
	give = min(rest, 8)
	tot += give
	rest -= give
	if tot >= k:
		break
if tot >= k:
	print(d)
else:
	print(-1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
k = 0
a = 0
for i in l:
	k += 1
	if i >= 8:
		c += 8
		a += i - 8
	elif i < 8:
		if i + a <= 8:
			c += i + a
			a = 0
		elif i + a > 8:
			c += 8
			a = i + a - 8
	if c >= m:
		print(k)
		break
else:
	print(-1)


(n, b) = map(int, input().split())
L = list(map(int, input().split()))
suma = 0
cont = 0
for k in range(n):
	suma += L[k]
	b -= min(8, suma)
	suma -= min(8, suma)
	cont += 1
	if b <= 0:
		break
if b <= 0:
	print(cont)
else:
	print(-1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
t = 0
k = 0
for i in range(n):
	m = m - min(t + l[i], 8)
	t = max(t + l[i] - 8, 0)
	k = k + 1
	if m <= 0:
		print(k)
		break
if m > 0:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
su = 0
for i in range(n):
	su += l[i]
	if su >= 8:
		su -= 8
		k -= 8
	else:
		k -= su
		su = 0
	if k < 1:
		print(i + 1)
		exit()
print(-1)


(n, k) = [int(_) for _ in input().split()]
(arya, bran) = (0, 0)
sweets = [int(_) for _ in input().split()]
for i in range(n):
	arya += sweets[i]
	bran += min(arya, 8)
	arya -= min(arya, 8)
	if bran >= k:
		print(i + 1)
		break
else:
	print(-1)


(m, a) = map(int, input().split())
line = input().split()
day = 1
buffer_ = 0
for i in line:
	ci = int(i)
	buffer_ += ci
	a -= min(buffer_, 8)
	if buffer_ >= 8:
		buffer_ -= 8
	else:
		buffer_ = 0
	if a <= 0:
		break
	day += 1
print(day if a <= 0 else -1)


(n, k) = map(int, input().split())
l = list(map(int, input().split())) + [0]
c = 0
s = 0
for i in range(n):
	if s < k:
		s = s + min(8, l[i])
		c = c + 1
		l[i + 1] = max(0, l[i] - 8) + l[i + 1]
if s < k:
	print(-1)
else:
	print(c)


def main():
	(n, k) = [int(x) for x in input().split()]
	doces = [int(x) for x in input().split()]
	print(solve(n, k, doces))

def solve(n, k, doces):
	resto = 0
	for i in range(n):
		if doces[i] > 8:
			k -= 8
			if i < n - 1:
				doces[i + 1] += doces[i] - 8
		else:
			k -= doces[i]
		if k <= 0:
			return i + 1
	return -1
main()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(n - 1):
	m1 = min(l[i], 8, k)
	k -= m1
	l[i + 1] += l[i] - m1
	if k == 0:
		break
if k == 0:
	print(i + 1)
elif l[n - 1] >= k and k <= 8:
	print(n)
else:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
(s, f, r) = (0, 0, 0)
for i in range(n):
	r += l[i]
	if s < k:
		if r > 8:
			s += 8
			r -= 8
		else:
			s += r
			r = 0
	if s >= k:
		f = 1
		break
if f == 1:
	print(i + 1)
else:
	print(-1)


def main():
	(n, k) = (int(x) for x in input().split())
	xs = [int(x) for x in input().split()]
	counter = 0
	arya = 0
	bran = 0
	for (i, x) in enumerate(xs):
		arya += x
		give = min(arya, 8)
		arya -= give
		bran += give
		if bran >= k:
			break
	if bran >= k:
		print(i + 1)
	else:
		print(-1)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
m = list(map(int, input().split()))
arya = 0
sweet = 0
day = 0
ans = -1
for i in m:
	day += 1
	if i > 8:
		sweet += 8
		arya += i - 8
	elif arya + i >= 8:
		sweet += 8
		arya -= 8 - i
	else:
		sweet += i + arya
		arya = 0
	if sweet >= k:
		ans = day
		break
print(ans)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
candies = left = cnt = 0
for i in range(n):
	candies = min(a[i] + left, 8, k)
	k -= candies
	left += a[i] - candies
	cnt += 1
	if k <= 0:
		break
if k <= 0:
	print(cnt)
else:
	print('-1')


(n, k) = map(int, input().split())
ls = list(map(int, input().split()))
stock = 0
for i in range(n):
	stock += ls[i]
	give = min(8, stock)
	stock -= give
	k -= give
	if k <= 0:
		break
print([-1, i + 1][k <= 0])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
have = 0
for i in range(0, n):
	have += l[i]
	x = min(8, have)
	k -= x
	have -= x
	if k <= 0:
		print(i + 1)
		exit()
print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
ost = 0
for i in range(n):
	ans += min(8, a[i] + ost)
	if a[i] > 8:
		ost += a[i] - 8
	elif a[i] < 8 and ost > 0:
		ost = max(0, ost - 8 + a[i])
	if ans >= k:
		print(i + 1)
		exit()
print(-1)


(n, k) = map(int, input().split())
a = [i for i in map(int, input().split())]
needed = 0
times = 0
for (i, j) in enumerate(a):
	needed += j
	mins = min(needed, 8)
	needed -= mins
	k -= mins
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
for i in range(n):
	r = min(8, arr[i], k)
	if i != n - 1:
		arr[i + 1] += arr[i] - r
	k -= r
	if k == 0:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = -1
s = 0
ai = 0
for i in range(n):
	ai += a[i]
	d = min(8, ai)
	s += d
	ai -= d
	if s >= k:
		ans = i + 1
		break
print(ans)


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	total = 0
	for i in range(n):
		cur = min(total + a[i], 8)
		k -= cur
		total += a[i] - cur
		if k <= 0:
			return i + 1
	if k > 0:
		return -1
print(solve())


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
c = 0
g = []
l = 0
if k == 0:
	print(-1)
else:
	for i in a:
		if i > 8:
			l = l + i - 8
			k -= 8
			c += 1
			if k <= 0:
				break
		else:
			x = 8 - i
			if l >= 0 and l <= x:
				k = k - i - l
				l = 0
			elif l >= 0 and l > x:
				k = k - i - x
				l = l - x
			else:
				k = k - i
			c += 1
			if k <= 0:
				break
	if k > 0:
		print(-1)
	else:
		print(c)


(n, k) = map(int, input().split())
ll = list(map(int, input().split()))
day = 0
zapas = 0
for i in ll:
	if k <= 0:
		break
	else:
		k -= min(8, zapas + i)
		zapas += i - min(8, zapas + i)
		day += 1
print(day if k <= 0 else -1)


(n, k) = map(int, input().split())
total = 0
ls = list(map(int, input().split()))
for (x, can) in enumerate(ls):
	total += can
	if total > 8:
		k -= 8
		total -= 8
	else:
		k -= total
		total = 0
	if k <= 0:
		print(x + 1)
		break
if k > 0:
	print(-1)


import sys
nk = list(map(int, input().split()))
candies = list(map(int, input().split()))
n = nk[0]
k = nk[1]
count = 0
flag = 0
i = 0
while k > 0 and i < n:
	if candies[i] > 8:
		if i + 1 < n:
			candies[i + 1] += candies[i] - 8
		candies[i] = 8
		if nk[1] - count >= candies[i]:
			count += candies[i]
			k -= candies[i]
		elif nk[1] - count < candies[i]:
			count += nk[1] - count
			k -= nk[1] - count
		i += 1
	elif candies[i] <= 8:
		if nk[1] - count >= candies[i]:
			count += candies[i]
			k -= candies[i]
		elif nk[1] - count < candies[i]:
			count += nk[1] - count
			k -= nk[1] - count
		i += 1
	if count == nk[1]:
		flag = 1
		print(i)
		break
if flag == 0:
	print(-1)


(n, k) = [int(x) for x in input().split()]
data = list(map(int, input().split()))
days = 0
remaining = 0
given = 0
x = True
for i in range(n):
	remaining += data[i]
	if given >= k:
		break
	elif remaining >= 8:
		given += 8
		remaining -= 8
		days += 1
	elif remaining < 8:
		given += remaining
		remaining = 0
		days += 1
	if i == n - 1 and given < k:
		print('-1')
		x = False
if x == True:
	print(days)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
i = 0
r = 0
ans = 0
g = 0
while n != 0:
	n -= 1
	g += l[i]
	r = min(8, g)
	g -= r
	k -= r
	ans += 1
	i += 1
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(ans)


(n, k) = list(map(int, input().split()))
N = list(map(int, input().split()))
Arya_candy = 0
Bran_candy = 0
count = 0
for i in range(len(N)):
	if N[i] + Arya_candy < 8:
		Bran_candy += N[i] + Arya_candy
		Arya_candy = 0
	else:
		Arya_candy += N[i] - 8
		Bran_candy += 8
	count += 1
	if Bran_candy >= k:
		break
if Bran_candy >= k:
	print(count)
else:
	print('-1')


(n, k) = map(int, input().split(' '))
arr = [int(i) for i in input().split(' ')]
(cnt, sum, save) = (0, 0, 0)
i = 0
while i < n and sum < k:
	if arr[i] >= 8:
		sum += 8
		save += arr[i] - 8
	else:
		sum += min(8, arr[i] + save)
		save = max(0, save - (8 - arr[i]))
	i += 1
	cnt += 1
print(cnt if sum >= k else -1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
import math
if math.ceil(k / 8) > n or sum(a) < k:
	print(-1)
else:
	res = 0
	c = 0
	for i in a:
		res += i
		temp = min(8, res)
		k -= temp
		res -= temp
		c += 1
		if k <= 0:
			break
	if k > 0:
		print(-1)
	else:
		print(c)


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
totalcandygiven = 0
candysupply = 0
done = False
for i in range(n):
	candysupply += a[i]
	if candysupply <= 8:
		totalcandygiven += candysupply
		candysupply = 0
	else:
		totalcandygiven += 8
		candysupply -= 8
	if totalcandygiven >= k:
		done = True
		break
if done:
	print(i + 1)
else:
	print(-1)


from math import ceil, sqrt, floor
import sys
(n, k) = map(int, input().split())
tt = 0
for (jour, i) in enumerate(map(int, input().split())):
	tt += i
	aRetirer = min(8, tt)
	k -= aRetirer
	tt -= aRetirer
	if k <= 0:
		break
print([-1, jour + 1][k <= 0])


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
car = 0
for i in range(n):
	lis[i] += car
	car = max(lis[i] - 8, 0)
	lis[i] = min(8, lis[i])
day = 0
found = 0
for i in range(n):
	day += lis[i]
	if day >= k:
		found = 1
		day = i
		break
if not found:
	print(-1)
else:
	print(day + 1)


(n, k) = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
tot = 0
saved = 0
for i in range(n):
	temp = min(8, saved + q[i])
	if temp == 8:
		saved += q[i] - 8
	else:
		saved = 0
	tot += temp
	if tot >= k:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
for i in range(len(a)):
	if a[i] >= 8:
		sum += 8
		if i != len(a) - 1:
			a[i + 1] += a[i] - 8
	else:
		sum += a[i]
	if sum >= k:
		print(i + 1)
		exit()
if sum < k:
	print('-1')
else:
	print(n)


(n, k) = map(int, input().split())
count = 1
rem = 0
total = 0
for i in list(map(int, input().split())):
	if count <= n:
		i += rem
		if i > 8:
			rem = i - 8
			i = 8
		else:
			rem = 0
		total += i
		if total >= k:
			print(count)
			break
		count += 1
	else:
		print(-1)
		break
if count > n:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = r = d = 0
for i in range(n):
	if b >= k:
		break
	t = r + a[i]
	s = t - 8
	b += min(t, 8)
	d += 1
	r = max(s, 0)
if b >= k:
	print(d)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
l = list(map(int, input().split()))
days = 0
stock = 0
while k > 0 and days < n:
	stock += l[days]
	k -= min(stock, 8)
	stock -= min(stock, 8)
	days += 1
if k > 0:
	print(-1)
else:
	print(days)


(n, k) = map(int, input().split())
lst = list(map(int, input().split()))
if n == 1 and lst[0] > 8 and (k > 8):
	print(-1)
	exit()
if n == 1 and k < 8 and (k < lst[0]):
	print(1)
	exit()
i = 0
d = 0
l = 0
while True:
	l += lst[d]
	i += min(8, l)
	l -= min(8, l)
	d += 1
	if i >= k:
		print(d)
		exit()
	if d == n:
		print(-1)
		exit()


(n, d) = map(int, input().split(' '))
m = list(map(int, input().split(' ')))
k = 0
f = 0
p = True
for i in range(n):
	if m[i] < 8:
		k += m[i]
		if 8 - m[i] <= f:
			f -= 8 - m[i]
			k += 8 - m[i]
		else:
			k += f
			f = 0
	else:
		f += m[i] - 8
		k += 8
	if k >= d:
		print(i + 1)
		p = False
		break
if p:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cnt = 0
ans = 0
for a in l:
	ans += 1
	cnt += a
	gt = min(8, min(cnt, k))
	k -= gt
	cnt -= gt
	if k == 0:
		print(ans)
		exit()
print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(ans, s) = (-1, 0)
for z in range(n):
	if a[z] > 8:
		s += 8
		if z < n - 1:
			a[z + 1] += a[z] - 8
	else:
		s += a[z]
	if s >= k:
		ans = z + 1
		break
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
res = 0
tmp = 0
for i in range(n):
	a[i] += tmp
	tmp = 0
	res += min(8, a[i])
	tmp += max(0, a[i] - 8)
	if res >= k:
		print(i + 1)
		quit()
print(-1)


(n, k) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
candy = 0
given = 0
c = 0
suc = False
for i in a:
	c += 1
	candy += i
	cangive = min(8, candy)
	candy -= cangive
	given += cangive
	if given >= k:
		suc = True
		break
if suc:
	print(c)
else:
	print(-1)


(n, k) = map(int, input().split())
Input = list(map(int, input().split()))
(count, ans) = (0, 0)
for i in range(n):
	(ans, count) = (ans + min(Input[i], 8), count + 1)
	if i < n - 1:
		Input[i + 1] += max(Input[i] - 8, 0)
	if ans >= k:
		break
else:
	count = -1
print(count)


def chop():
	return (int(i) for i in input().split())
(n, k) = chop()
r = 0
x = 0
i = 0
f = False
a = [int(i) for i in input().split()]
while k > 0:
	if x == n:
		f = True
		break
	x += 1
	c = a[i]
	if c + r > 8:
		k -= 8
		r = r + c - 8
	else:
		k -= r + c
		r = 0
	if k <= 0:
		break
	i += 1
print('-1' if f else x)


(n, k) = tuple(map(int, input().split()))
candies = list(map(int, input().split()))
stored_candies = 0
for (i, candy) in enumerate(candies):
	stored_candies += candy
	to_give = min(8, stored_candies)
	stored_candies -= to_give
	k -= to_give
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(i + 1)


(x, y) = map(int, input().split(' '))
z = input()
a = []
i = 0
while i < x:
	a.append(int(z.split(' ')[i]))
	i = i + 1
b = 0
for ind in range(x):
	b = b + a[ind]
	d = min(8, b)
	b = b - d
	y = y - d
	if y <= 0:
		exit(print(ind + 1))
		break
print(-1)


(n, k) = input().strip().split()
n = int(n)
k = int(k)
a = [int(g) for g in input().split()]
s = 0
i = 0
p = 0
while s <= k and i < n:
	a[i] = a[i] + p
	if a[i] > 8:
		s += 8
		p = a[i] - 8
		if s == k:
			i += 1
			break
	else:
		s += a[i]
		p = 0
		if s == k:
			i += 1
			break
	i += 1
if i <= n and s >= k:
	print(i)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
candy = 0
storage = 0
for i in a:
	if candy >= k:
		break
	ans += 1
	if i < 8 and i + storage >= 8:
		candy += 8
		storage -= 8 - i
	elif i < 8:
		candy += i + storage
		storage = 0
	else:
		candy += 8
		storage += i - 8
if candy >= k:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
candy = list(map(int, input().split()))
extra = 0
total = 0
for i in range(1, n + 1, 1):
	extra += candy[i - 1]
	if extra >= 8:
		total += 8
		extra -= 8
	else:
		total += extra
		extra = 0
	if total >= k:
		print(i)
		break
	if i == n:
		print(-1)


(_, k) = map(int, input().split())
(r, c) = (0, 0)
for x in map(int, input().split()):
	r += 1
	c += x
	d = min(c, 8)
	c -= d
	k -= d
	if k < 1:
		break
print([r, -1][k > 0])


def Main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	for _ in range(n, 102):
		arr.append(0)
	sm = 0
	cnt = 0
	rem = 0
	idx = 0
	for i in range(n):
		if arr[i] > 8:
			sm += 8
			rem += arr[i] - 8
			arr[i + 1] = arr[i + 1] + rem
			rem = 0
		else:
			sm += arr[i]
		if sm >= k:
			idx = i + 1
			break
	if sm < k or idx > n:
		print(-1)
	else:
		print(idx)
Main()


(n, k) = map(int, input().split())
sum = 0
days = [int(i) for i in input().split(' ')]
arya = 0
bran = 0
for i in range(0, n):
	arya += days[i]
	if arya <= 8:
		bran += arya
		arya = 0
	else:
		bran += 8
		arya -= 8
	if bran >= k:
		print(i + 1)
		break
if bran < k:
	print('-1')


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]
cur = 0
ans = 0
for i in range(0, n):
	cur += a[i]
	r = min(cur, 8)
	cur -= r
	k -= r
	ans += 1
	if k <= 0:
		break
if k > 0:
	print('-1')
else:
	print(ans)


(n, k) = map(int, input().split())
li = list(map(int, input().split()))
s = 0
reserve = 0
day = 0
for (ind, candy) in enumerate(li):
	if candy < 8:
		s += candy
		if reserve > 8 - candy:
			reserve -= 8 - candy
			s += 8 - candy
		else:
			s += reserve
			reserve = 0
	else:
		s += 8
		reserve += candy - 8
	if s >= k:
		print(ind + 1)
		break
else:
	print(-1)


c = list(map(int, input().split(' ')))
n = c[0]
k = c[1]
sum = 0
b = list(map(int, input().split(' ')))
for i in range(n):
	if b[i] > 8:
		if i < n - 1:
			b[i + 1] = b[i + 1] + b[i] - 8
for i in range(n):
	if b[i] <= 8:
		sum = sum + b[i]
	else:
		sum = sum + 8
if sum < k:
	print(-1)
else:
	sum = 0
	i = 0
	while sum < k:
		if b[i] <= 8:
			sum = sum + b[i]
		else:
			sum = sum + 8
		i = i + 1
	print(i)


(n, k) = input().split(' ')
n = int(n)
k = int(k)
candylist = [int(i) for i in input().split(' ')]
given = 0
days = 0
remaining = 0
for candy in candylist:
	if candy <= 8:
		given += candy
		if remaining != 0:
			if remaining >= 8 - candy:
				given += 8 - candy
				remaining -= 8 - candy
			else:
				given += remaining
				remaining = 0
		days += 1
	else:
		given += 8
		remaining += candy - 8
		days += 1
	if given >= k:
		print(days)
		break
if given < k:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = d = flag = 0
while k > 0:
	d += 1
	if a[i] <= 8:
		k -= a[i]
	else:
		k -= 8
		if i != n - 1:
			a[i + 1] += a[i] - 8
	if k <= 0:
		flag = 1
		break
	if d == n:
		break
	i += 1
if flag == 0:
	print(-1)
else:
	print(d)


(n, k) = map(int, input().split(' '))
t = 1
s = 0
A = list(map(int, input().split(' ')))
for i in range(n):
	s += A[i]
	if s > 8:
		k -= 8
		s -= 8
	else:
		k -= s
		s = 0
	if k > 0:
		t += 1
if k <= 0:
	print(t)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
t = list(map(int, input().split()))
p = sum(t)
if p >= k:
	(o, d, s) = (0, 0, 0)
	for j in range(n):
		if t[j] <= 8:
			if d + t[j] > 8:
				o += 8
				d = d + t[j] - 8
			else:
				o += d + t[j]
				d = 0
		else:
			o += 8
			d += t[j] - 8
		if o >= k:
			print(j + 1)
			s += 1
			break
	if s == 0:
		print(-1)
else:
	print(-1)


(n, k) = (int(x) for x in input().split())
arr = [int(x) for x in input().split()]
have = 0
for (day, candy) in enumerate(arr, start=1):
	have += candy
	give = min(have, 8)
	k -= give
	have -= give
	if k <= 0:
		print(day)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
count = 0
flag = 0
pos = 0
a = [int(x) for x in input().split()]
for i in range(n):
	if a[i] > 8:
		if i != n - 1:
			count = count + 8
			a[i + 1] += abs(a[i] - 8)
		elif a[i] > 8:
			count += 8
		else:
			count += a[i]
	else:
		count += a[i]
	if count >= k:
		pos = i + 1
		flag = 1
		break
if flag:
	print(pos)
else:
	print('-1')


import sys
import re
import math
import collections
import itertools
import functools
DEBUG = True
DEBUG = False

def dbg(*args):
	if DEBUG:
		print('DBG: ', file=sys.stderr, end='')
		print(*args, file=sys.stderr)

def main():
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	candy_a = 0
	candy_b = 0
	for day in range(N):
		candy_a += A[day]
		if candy_a > 8:
			candy_b += 8
			candy_a -= 8
		else:
			candy_b += candy_a
			candy_a = 0
		if candy_b >= K:
			print(day + 1)
			return
	print(-1)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, list(input().split()))
a = [int(i) for i in list(input().split())]
s = 0
f = 0
c = 0
for i in range(n):
	if a[i] > 8:
		s += 8
	else:
		s += a[i]
	if s >= k:
		f = 1
		break
	if i < n - 1 and a[i] - 8 > 0:
		a[i + 1] = a[i + 1] + a[i] - 8
	i += 1
	c += 1
if f == 0:
	print(-1)
else:
	print(c + 1)


def arja(lst, k):
	(count1, count2) = (0, 0)
	for i in range(len(lst)):
		count2 += lst[i]
		if count2 >= 8:
			count1 += 8
			count2 -= 8
		else:
			count1 += count2
			count2 = 0
		if count1 >= k:
			return i + 1
	return -1
(n, K) = [int(j) for j in input().split()]
b = [int(x) for x in input().split()]
print(arja(b, K))


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
	c = min(k, a[i], 8)
	if i != n - 1:
		a[i + 1] += a[i] - c
	k -= c
	if k == 0:
		print(i + 1)
		break
else:
	print('-1')


(n, k) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
A = 0
B = 0
result = -1
for i in range(len(a)):
	A += a[i]
	t = min(8, A)
	B += t
	A -= t
	if B >= k:
		result = i + 1
		break
print(result)


def main():
	(n, k) = list(map(int, input().split()))
	candies = list(map(int, input().split()))
	rest = 0
	given = 0
	for i in range(n):
		rest += candies[i]
		if rest >= 8:
			given += 8
			rest -= 8
		else:
			given += rest
			rest = 0
		if given >= k:
			print(i + 1)
			break
		if i == n - 1:
			print(-1)

def __starting_point():
	main()
__starting_point()


(n, k) = list(map(int, input().split()))
candies = list(map(int, input().split()))

def days(candies, k):
	left = 0
	bryan = 0
	days = 1
	for x in candies:
		if x <= 8:
			if left + x >= 8:
				bryan += 8
				left = left + x - 8
			else:
				bryan = bryan + x + left
				left = 0
		else:
			left += x - 8
			bryan += 8
		if bryan >= k:
			return days
		days += 1
	return -1
print(days(candies, k))


(n, k) = map(int, input().split())
a = map(int, input().split())
ans = 0
sum = 0
for i in a:
	sum += i
	if sum >= 8:
		k -= 8
		sum -= 8
	else:
		k -= sum
		sum = 0
	ans += 1
	if k <= 0:
		print(ans)
		break
if k > 0:
	print('-1')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
rem = 0
for a in arr:
	if a >= 8:
		k -= 8
		rem += a - 8
	elif a + rem >= 8:
		k -= 8
		rem += a - 8
	else:
		k -= a + rem
		rem = 0
	count += 1
	if k <= 0:
		break
print(-1 if k > 0 else count)


(n, k) = [int(x) for x in input().split()]
mas = [int(x) for x in input().split()]
s = sum(mas)
if 8 * n < k or s < k:
	print(-1)
	quit()
p = 0
i = 1
b = 0
for j in mas:
	p += j
	u = min(8, p)
	p -= u
	b += u
	if b >= k:
		print(i)
		quit()
	i += 1
print(-1)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
s = 0
for i in range(a):
	s += c[i]
	d = min(s, 8)
	s -= d
	b -= d
	if b <= 0:
		exit(print(i + 1))
print(-1)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import defaultdict
import sys
import math
MAX = sys.maxsize
MAXN = 10 ** 6 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()
(n, k) = numIN()
l = list(numIN())
ans = 0
for i in range(n):
	ans += l[i]
	k -= min(ans, 8)
	ans -= min(ans, 8)
	if k <= 0:
		print(i + 1)
		exit(0)
print(-1)


import sys
(N, K) = map(int, input().split())
a_ls = list(map(int, input().split()))
co = 0
total = 0
for i in range(N):
	if a_ls[i] == 8:
		total += 8
	elif a_ls[i] > 8:
		co += a_ls[i] - 8
		total += 8
	else:
		lack = 8 - a_ls[i]
		if co >= lack:
			total += 8
			co -= lack
		else:
			total += a_ls[i] + co
			co = 0
	if total >= K:
		print(i + 1)
		sys.exit()
print(-1)


def zjistit():
	(n, k) = map(int, input().split())
	dny = list(map(int, input().split()))
	buffer = 0
	for i in range(n):
		dny[i] += buffer
		buffer = 0
		if dny[i] >= k and k <= 8:
			return i + 1
		if dny[i] > 8:
			k -= 8
			buffer += dny[i] - 8
		else:
			k -= dny[i]
	return -1
print(zjistit())


(n, k) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
j = 0
day = 0
m = 0
while j < k and day != n:
	day += 1
	if a[day - 1] + m <= 8:
		j += a[day - 1] + m
		m = 0
	else:
		j += 8
		m += a[day - 1] - 8
if j >= k:
	print(day)
else:
	print(-1)


(n, k) = map(int, input().split())
li = [int(x) for x in input().split(' ')]
sum = 0
for i in range(0, len(li)):
	sum = sum + li[i]
	if sum >= 8:
		k -= 8
		sum -= 8
	else:
		k -= sum
		sum = 0
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(i + 1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
i = 0
h = 0
s = 0
ans = -1
while i < n:
	x = arr[i]
	h += x
	if h > 8:
		h -= 8
		s += 8
	else:
		s += h
		h = 0
	if s >= k:
		ans = i + 1
		break
	i += 1
print(ans)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
sweets = 0
for i in range(n):
	sweets += a[i]
	given = min(sweets, 8)
	sweets -= given
	k -= given
	if k <= 0:
		print(i + 1)
		break
if k > 0:
	print(-1)


(n, k) = input().split()
n = int(n)
k = int(k)
a = list(map(int, input().split()))
if k > n * 8 or k > sum(a):
	print(-1)
else:
	cr = 0
	for (i, _a) in enumerate(a, start=1):
		cr += _a
		k = k - min(8, cr)
		cr -= min(8, cr)
		if k <= 0:
			print(i)
			break
	else:
		print(-1)


(n, k) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
(arya, bryan) = (0, 0)
ans = -1
for i in range(n):
	arya += a[i]
	bryan += min(8, arya)
	arya -= min(8, arya)
	if bryan >= k:
		ans = i + 1
		break
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
t = 0
for i in range(n):
	t += a[i]
	k -= min(8, t)
	t -= min(t, 8)
	ans += 1
	if k <= 0:
		exit(print(ans))
print(-1)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = 0
c = 0
d = 0
ans = 0
for i in range(n):
	a[i] += c
	if a[i] > 8:
		c = a[i] - 8
		b += 8
		ans += 1
	else:
		b += a[i]
		ans += 1
		c = 0
	if b >= k:
		print(ans)
		break
	if b < k and i + 1 == n:
		print('-1')


(n, k) = input().split()
hand = 0
brot = int(k)
a = list(map(int, input().split()))
for i in range(int(n)):
	if a[i] > 8:
		brot -= 8
		hand += a[i] - 8
	else:
		brot -= min(a[i] + hand, 8)
		hand = max(hand - 8 + a[i], 0)
	if brot <= 0:
		days = i + 1
		break
if brot > 0:
	print(-1)
else:
	print(days)


[n, k] = input().strip().split()
n = int(n)
k = int(k)
days = -1
numCandies = 0
n_array = input().strip().split()
for x in range(n):
	val = int(n_array[x])
	numCandies += val
	if numCandies >= 8:
		k -= 8
		numCandies -= 8
	else:
		k -= numCandies
		numCandies = 0
	if k <= 0:
		days = x + 1
		break
print(days)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = 0
c = 0
while k > 0:
	try:
		a[c] += b
		b = 0
		if a[c] <= 8:
			k -= a[c]
		else:
			k -= 8
			b = b + (a[c] - 8)
		c += 1
	except:
		print('-1')
		break
if k <= 0:
	print(c)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
d = 0
c = 0
t = 0
while t < k:
	if d == n:
		d += 1
		break
	c += a[d]
	g = min(8, c)
	t += g
	d += 1
	c = c - g
if d == n + 1:
	print(-1)
else:
	print(d)


(n, k) = list(map(int, input().rstrip().split()))
days = list(map(int, input().rstrip().split()))
r = 0
for (i, a) in enumerate(days):
	if a + r > 8:
		r += a - 8
		k -= 8
	else:
		k -= a + r
		r = 0
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
given = 0
arya = 0
for i in range(n):
	arya += a[i]
	given += min(8, arya)
	arya = max(arya - 8, 0)
	if given >= k:
		print(i + 1)
		sys.exit()
print(-1)


(q, w) = map(int, input().split())
a = list(map(int, input().split()))
if (w > 8 * q) | (w > sum(a)):
	print(-1)
else:
	s = 0
	i = 0
	while (w > 0) & (i < q):
		s += a[i]
		w -= min(8, s)
		s -= min(8, s)
		i += 1
	if w <= 0:
		print(i)
	else:
		print(-1)


(n, k) = input().split()
n = int(n)
k = int(k)
leftovers = 0
candies_map = map(int, input().split())
candies = list(candies_map)
completed = False
for i in range(n):
	if candies[i] >= 8:
		k -= 8
		leftovers += candies[i] - 8
	else:
		k -= candies[i]
		if leftovers >= 8 - candies[i]:
			k -= 8 - candies[i]
			leftovers -= 8 - candies[i]
		else:
			k -= leftovers
			leftovers = 0
	if k <= 0:
		print(i + 1)
		completed = True
		break
if not completed:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
current = 0
x = -1
for i in range(n):
	current += a[i]
	k -= min(current, 8)
	current -= min(current, 8)
	if k <= 0:
		x = i + 1
		break
print(x)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
col_a = 0
col_b = 0
for i in range(n):
	col_a += a[i]
	if col_a >= 8:
		col_a -= 8
		col_b += 8
	else:
		col_b += col_a
		col_a = 0
	if col_b >= k:
		print(i + 1)
		break
if col_b < k:
	print('-1')


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
sum = 0
count = 0
for i in range(n):
	if l[i] <= 8:
		sum += l[i]
		count += 1
	elif l[i] > 8 and i != n - 1:
		sum += 8
		l[i + 1] += l[i] - 8
		count += 1
	elif i == n - 1:
		sum += 8
		count += 1
	if sum >= k:
		break
if sum >= k:
	print(count)
else:
	print(-1)


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
flag = 1
candies = 0
for i in range(n):
	candies += l[i]
	if candies > k:
		candies -= min(8, k)
		k -= min(8, k)
	else:
		k -= min(8, candies)
		candies -= min(8, candies)
	if k == 0:
		flag = 0
		print(i + 1)
		break
if flag == 1:
	print(-1)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
cur = 0
day = -1
for (i, q) in enumerate(A):
	cur += q
	if cur <= 8:
		k -= cur
		cur = 0
	elif cur >= 8:
		k -= 8
		cur -= 8
	if k <= 0:
		day = i + 1
		break
print(day)


(n, k) = map(int, input().split())
a = list(map(int, input().strip().split()))
rem = 0
total = 0
index = 0
for i in a:
	index += 1
	if rem + i <= 8:
		total += rem + i
		rem = 0
	else:
		rem += i - 8
		total += 8
	if total >= k:
		break
if total >= k:
	print(index)
else:
	print('-1')


(n, k) = map(int, input().split())
p = 0
d = 0
a = list(map(int, input().split())) + [0]
for i in range(n):
	if p < k:
		p = p + min(8, a[i])
		d += 1
		a[i + 1] = max(0, a[i] - 8) + a[i + 1]
print(-1 if p < k else d)


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
bank = 0
count = 0
for i in lis:
	if k <= 0:
		break
	if bank + i > 8:
		k -= 8
		count += 1
		bank = bank + i - 8
	else:
		k = k - (bank + i)
		count += 1
		bank = 0
print(count) if k <= 0 else print(-1)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c = 0
day = 0
for i in range(n):
	c += a[i]
	if k > 0:
		day += 1
		if c > 8:
			k -= 8
			c -= 8
		else:
			k -= c
			c = 0
	else:
		break
if k <= 0:
	print(day)
else:
	print('-1')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(i, t) = (1, 0)
while i - 1 < n:
	t += a[i - 1]
	k -= min([8, t])
	t -= min(8, t)
	if k <= 0:
		print(i)
		exit()
	i += 1
print(-1)


(n, k) = map(int, input().split())
a = list(input().split())
if k // 8 > n:
	print(-1)
else:
	j = []
	for i in range(n):
		j += [int(a[i])]
	j += [0]
	g = 0
	for i in range(n + 1):
		if j[i] > 8:
			k -= 8
			j[i + 1] += j[i] - 8
			g += 1
			if k <= 0:
				break
		else:
			k -= j[i]
			g += 1
			if k <= 0:
				break
	if g <= n:
		print(g)
	else:
		print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = 0
ost = 0
i = 0
f = 0
while t < k and i < n:
	if ost >= 8:
		ost -= 8
		t += 8
		ost += a[i]
	else:
		t += ost
		f = 8 - ost
		if a[i] > f:
			t += f
			ost = a[i] - f
		else:
			t += a[i]
			ost = 0
	i += 1
if t < k:
	print(-1)
else:
	print(i)


(n, k) = [int(i) for i in input().split()]
arr = [int(j) for j in input().split()]
index = 0
A = 0
while index < n and k > 0:
	A += arr[index]
	if A > 8:
		k -= 8
		A -= 8
	else:
		k -= A
		A -= A
	index += 1
if k > 0:
	print(-1)
else:
	print(index)


nk = input().split(' ')
k = int(nk[1])
a = input().split(' ')
s = 0
d = 0
for i in a:
	d += 1
	s += int(i)
	if s > 8:
		s -= 8
		k -= 8
	else:
		k -= s
		s = 0
	if k <= 0:
		print(d)
		break
if k > 0:
	print(-1)


income = input().split()
n = int(income[0])
k = int(income[1])
income = input().split()
candies = [0] * n
totalCandiesGiven = 0
saved = 0
c = 0
for i in range(n):
	candies[i] = int(income[i])
	if candies[i] > 8:
		totalCandiesGiven += 8
		saved += candies[i] - 8
	else:
		totalCandiesGiven += candies[i]
		if 8 - candies[i] >= saved:
			totalCandiesGiven += saved
			saved = 0
		else:
			totalCandiesGiven += 8 - candies[i]
			saved -= 8 - candies[i]
	if totalCandiesGiven >= k:
		c = 1
		print(i + 1)
		break
if c == 0:
	print(-1)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()][:n]
d = 0
e = 0
if k > sum(a):
	print(-1)
else:
	for item in a:
		if item + e >= 8:
			k -= 8
			e += item - 8
		else:
			k -= item + e
			e = 0
		d += 1
		if k <= 0:
			print(d)
			break
		if d == n:
			print(-1)
			break


(n, k) = input().strip().split(' ')
(n, k) = (int(n), int(k))
l = list(map(int, input().strip().split(' ')))
s = 0
v = 0
ans = 0
for i in range(n):
	if s < k:
		ans += 1
	if l[i] <= 8:
		s += min(l[i] + v, 8)
		v = max(v - 8 + l[i], 0)
	elif l[i] > 8:
		s += 8
		v += l[i] - 8
if s >= k:
	print(ans)
else:
	print(-1)


import math

def AryaAndBran(n, k, a):
	totalCandies = sum(a)
	maxPossibleDays = math.ceil(k / 8)
	if totalCandies < k or n < maxPossibleDays:
		return -1
	i = 0
	sumCandiesPerDay = 0
	carryOver = 0
	carryOverNext = 0
	while i < n:
		carryOverNext = carryOver + a[i] - 8
		if carryOverNext > 0:
			sumCandiesPerDay += 8
			carryOver = carryOverNext
		else:
			sumCandiesPerDay += carryOver + a[i]
			carryOver = 0
		carryOverNext = 0
		if sumCandiesPerDay >= k:
			return i + 1
		i += 1
	return -1
(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
print(AryaAndBran(n, k, a))


(n, k) = map(int, input().split())
mat = list(map(int, input().split()))
stack = 0
for i in range(len(mat)):
	stack += mat[i]
	k -= min(8, stack)
	stack = max(0, stack - 8)
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


s1 = input()
n = int(s1.split()[0])
k = int(s1.split()[1])
s2 = input()
t = []
for i in range(0, n):
	t.append(int(s2.split()[i]))
temp = 0
art = 0
flag = 0
d = -1
for i in range(0, n):
	art += t[i]
	if art >= 8:
		temp += 8
		art -= 8
	else:
		temp += art
		art = 0
	if temp >= k:
		flag = 1
		d = i + 1
		break
if flag == 1:
	print(d)
else:
	print(d)


def adder(x, y):
	sum = 0
	for i in range(x, y):
		sum += l[i]
	return sum
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
days = 0
if k > 8 * n or adder(0, n) < k:
	print(-1)
else:
	for i in range(0, n):
		if k <= 0:
			break
		days += 1
		if l[i] <= 8:
			k -= l[i]
		else:
			k -= 8
			if i < n - 1:
				l[i + 1] += l[i] - 8
	if k <= 0:
		print(days)
	else:
		print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cur = 0
for i in range(0, n):
	cur += a[i]
	tmp = min(cur, 8)
	k -= tmp
	cur -= tmp
	if k <= 0:
		print(i + 1)
		exit(0)
print(-1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
array = list(map(int, input().split()))
total = 0
saved = 0
found = False
for day in range(n):
	saved += array[day]
	given = min(saved, 8)
	total += given
	saved -= given
	if total >= k:
		found = True
		print(day + 1)
		break
if not found:
	print(-1)


(n, k) = [int(s) for s in input().split()]
LIST = [int(s) for s in input().split()]
a = 0
b = 0
d = 0
for i in range(n):
	a += LIST[i]
	if a >= 8:
		a -= 8
		b += 8
		d += 1
	else:
		b += a
		a -= a
		d += 1
	if b >= k:
		print(d)
		break
if b < k:
	print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
container = 0
candies_given = 0
check = 0
for i in range(n):
	container += arr[i]
	if container >= 8:
		candies_given += 8
		container -= 8
	else:
		candies_given += container
		container = 0
	if candies_given >= k:
		check = 1
		print(i + 1)
		break
if check == 0:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
y = 0
while y < len(a) - 1:
	if a[y] > 8:
		a[y + 1] += a[y] - 8
		a[y] = 8
	k -= a[y]
	if k <= 0:
		print(y + 1)
		exit()
	y += 1
if a[len(a) - 1] > 8:
	a[len(a) - 1] = 8
if k - a[len(a) - 1] > 0:
	print(k - (k + 1))
else:
	print(n)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
s = 0
t = 0
ctr = 0
for i in range(n):
	if a[i] < 8:
		a[i] += t
		t = 0
	if a[i] >= 8:
		t += a[i] - 8
		a[i] = 8
for i in range(n):
	if s >= k:
		break
	s += a[i]
	ctr += 1
if s < k:
	print(-1)
else:
	print(ctr)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
count = tank = 0
for i in range(n):
	tank += a[i]
	if tank >= 8:
		count += 1
		tank -= 8
		k -= 8
	else:
		count += 1
		k -= tank
		tank = 0
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(count)


(n, k) = map(int, input().split(' '))
arr = [int(i) for i in input().split(' ')]
c = 0
rem = 0
result = False
days = 0
for i in arr:
	if i + rem <= 8:
		c += i + rem
		rem = 0
	else:
		c += 8
		rem = i + rem - 8
	if c >= k:
		result = True
		break
	else:
		days += 1
if result == True:
	print(days + 1)
else:
	print(-1)


(n, m) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
c = 0
for i in range(n):
	c += min(8, a[i])
	if i != n - 1:
		a[i + 1] += max(0, a[i] - 8)
	if c >= m:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
flag = 0
for i in range(n):
	if a[i] >= 8:
		sum += 8
		if i != n - 1:
			a[i + 1] += a[i] - 8
	else:
		sum += a[i]
	if sum >= k:
		print(i + 1)
		flag = 1
		break
if flag == 0:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
d = cnt = ans = 0
lim = 8
while d < n and k > 0:
	cnt += l[d]
	k -= min(cnt, lim)
	cnt -= min(cnt, lim)
	d += 1
if k > 0:
	print(-1)
else:
	print(d)


read = lambda : tuple(map(int, input().split()))
(n, k) = read()
l = read()
(sm, a) = (0, 0)
d = 0
for v in l:
	a += v
	sm += min(a, 8)
	a -= min(a, 8)
	d += 1
	if sm >= k:
		break
print(d if sm >= k else -1)


(n, m) = list(map(int, input().split()))
z = list(map(int, input().split()))
ans = 0
ctr = 0
left = 0
while ctr < m:
	if ans >= n:
		print(-1)
		return
	else:
		z[ans] += left
		ctr += min(8, z[ans])
		left = z[ans] - min(8, z[ans])
	ans += 1
print(ans)


(n, need) = [int(a) for a in input().split()]
candy = [int(a) for a in input().split()]
have = 0
for b in range(n):
	have += candy[b]
	if have > 8:
		have -= 8
		need -= 8
	else:
		c = have
		have -= have
		need -= c
	if need <= 0:
		print(b + 1)
		break
if need > 0:
	print('-1')


(n, k) = map(int, input().split())
ar = 0
br = 0
q = 0
for i in list(map(int, input().split())):
	q += 1
	ar += i
	br += min(ar, 8)
	ar -= min(ar, 8)
	if br >= k:
		print(q)
		exit()
print(-1)


n = list(map(int, input().split()))
a = list(map(int, input().split()))
n = n[1]
p = 0
t = 0
for i in a:
	i = i + p
	if n <= 0:
		break
	if i < 8:
		n = n - i
		p = 0
	else:
		n = n - 8
		p = i - 8
	t += 1
if n <= 0:
	print(t)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(s, f) = (0, 0)
for x in range(n):
	if a[x] > 8:
		s += 8
		f += a[x] - 8
	elif f > 0:
		s += a[x] + min(f, 8 - a[x])
		f -= min(f, 8 - a[x])
	else:
		s += a[x]
	if s >= k:
		print(x + 1)
		break
else:
	print(-1)


(n, kBran) = [int(i) for i in input().split()]
konf = input().split()
k = 0
ost = 0
f = True
for i in range(n):
	konf[i] = int(konf[i]) + ost
	ost = 0
	if int(konf[i]) <= 8:
		k = k + int(konf[i])
	else:
		k = k + 8
		ost = ost + int(konf[i]) - 8
	if k >= kBran:
		print(i + 1)
		f = False
		break
if f == True:
	print(-1)


import sys, os
(n, k) = map(int, input().split())
data = list(map(int, input().split()))
res = 0
resu = 0
for i in range(n):
	res += data[i]
	r = min(res, 8)
	res -= r
	resu += r
	if resu >= k:
		print(i + 1)
		exit(0)
		sys.exit
		os.abort()
print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
c = 0
temp = 0
for i in arr:
	temp += i
	if temp >= 8:
		c += 1
		temp -= 8
		k -= 8
	else:
		k -= temp
		temp = 0
		c += 1
	if k < 1:
		print(c)
		break
else:
	print(-1)


(n, k) = list(map(int, input().split()))
list = list(map(int, input().split()))
(z, t) = (0, 0)
for i in list[:]:
	z += i
	t += 1
	k -= min(z, 8)
	z -= min(z, 8)
	if k <= 0:
		print(t)
		exit()
print(-1)


(n, k) = map(int, input().split())
candies = [int(x) for x in input().split()]
a = 0
b = 0
for day in range(1, n + 1):
	a += candies[day - 1]
	c = min(8, a)
	b += c
	a -= c
	if b >= k:
		print(day)
		exit()
print(-1)


import sys

def main():
	(n, k) = map(int, sys.stdin.readline().split())
	candies = map(int, sys.stdin.readline().split())
	remaining = 0
	given = 0
	for (day, candy) in enumerate(candies):
		remaining += candy
		to_give = min(8, remaining)
		remaining -= to_give
		given += to_give
		if given >= k:
			print(day + 1)
			return
	print(-1)
main()


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
i = 0
buf = 0
while i < n:
	if l[i] + buf > 8:
		k = k - 8
		buf = buf + l[i] - 8
	else:
		k = k - buf - l[i]
		buf = 0
	i += 1
	if k <= 0:
		print(i)
		break
if k > 0:
	print(-1)


import sys

def main():
	(n, k) = map(int, sys.stdin.readline().split())
	x = list(map(int, sys.stdin.readline().split()))
	c = 0
	j = -1
	r = 0
	for i in range(n):
		r += x[i]
		g = min(8, r)
		c += g
		r -= g
		if c >= k:
			j = i + 1
			break
	print(j)
main()


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
if k > n * 8:
	print(-1)
else:
	togive = k
	have = 0
	day = 0
	for x in arr:
		day += 1
		have += x
		if togive > 8:
			j = min(have, 8)
			have = have - j
			togive = togive - j
		else:
			l = min(have, togive)
			have = have - l
			togive = togive - l
		if togive == 0:
			print(day)
			break
	if togive != 0:
		print(-1)


(d, c) = map(int, input().split(' '))
a = [int(x) for x in input().strip().split(' ')]
rem = 0
days = 0
for candles in a:
	if candles > 8:
		c -= 8
		rem += candles - 8
		days += 1
	else:
		if rem + candles > 8:
			c -= 8
			rem -= 8 - candles
		else:
			c -= rem + candles
			rem = 0
		days += 1
	if c <= 0:
		break
if c > 0:
	print('-1')
else:
	print(days)


(a, b) = input().split()
n = int(a)
k = int(b)
l = [int(i) for i in input().split()]
remain = 0
given = 0
ch = 0
for i in range(n):
	remain = remain + l[i]
	if remain > 8:
		given = given + 8
		remain = remain - 8
	else:
		given = given + remain
		remain = 0
	if given >= k:
		print(i + 1)
		ch = 1
		break
if ch == 0:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
saved = 0
candies_given = 0
for num in range(n):
	l[num] += saved
	saved = 0
	if l[num] <= 8:
		candies_given += l[num]
	else:
		saved = l[num] - 8
		candies_given += 8
	if candies_given >= k:
		print(num + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
a = map(int, input().split())

def solve():
	global n, k, a
	num = 0
	res = 0
	for i in a:
		num += i
		impart = min(8, num)
		k -= impart
		num -= impart
		res += 1
		if k <= 0:
			return print(res)
	print(-1)
solve()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
i = 0
t = 0
r = 0
while i < n and t < k:
	if a[i] + r < 8:
		t += a[i] + r
		r = 0
	else:
		t += 8
		r = a[i] + r - 8
	t = min(t, k)
	i += 1
if t == k:
	print(i)
else:
	print(-1)


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
suma = 0
i = 0
v = 0
while suma < k and i < n:
	if arr[i] + v < 8:
		suma += arr[i] + v
		v = 0
	else:
		suma += 8
		v += arr[i] - 8
	i += 1
if suma >= k:
	print(i)
else:
	print(-1)


def Min(a, b):
	a = int(a)
	b = int(b)
	if a < b:
		return a
	else:
		return b
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
now = 0
flag = False
ans = 0
for i in range(n):
	now = now + a[i]
	tmp = Min(now, 8)
	k = k - tmp
	now = now - tmp
	ans = ans + 1
	if k <= 0:
		flag = True
		break
if flag:
	print(ans)
else:
	print(-1)


import sys

def count_days(n, k, candies):
	days = 0
	valid_candies = 0
	if k == 0:
		return 0
	for i in range(n):
		if candies[i] < 8:
			valid_candies += candies[i]
		else:
			valid_candies += 8
			if i + 1 < n:
				candies[i + 1] += candies[i] - 8
		days += 1
		if valid_candies >= k:
			return days
	return -1

def main():
	(n, k) = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
	candies = list(map(int, sys.stdin.readline().rstrip('\n').split(' ')))
	print(count_days(n, k, candies))
main()


def Lorenzo(X, Y):
	if X <= 0:
		return 1
_0_ = list(map(int, input().split()))
_1_ = list(map(int, input().split()))
_LEN_ = len(_1_)
if _0_[0] * 8 < _0_[1] or sum(_1_) < _0_[1]:
	print(-1)
else:
	for _2_ in range(_0_[0]):
		if _1_[_2_] > 8:
			_0_[1] -= 8
			if Lorenzo(_0_[1], _2_ + 1) == 1:
				print(_2_ + 1)
				exit(0)
			elif _2_ == _LEN_ - 1:
				print(-1)
				exit(0)
			else:
				_1_[_2_ + 1] += _1_[_2_] - 8
		else:
			_0_[1] -= _1_[_2_]
			if Lorenzo(_0_[1], _2_ + 1) == 1:
				print(_2_ + 1)
				exit(0)


from sys import stdin
(n, k) = [int(i) for i in stdin.readline().split(' ')]
candyGains = [int(i) for i in stdin.readline().split(' ')]
stash = 0
candiesGiven = 0
for i in range(0, n):
	stash += candyGains[i]
	candiesGiven += min(8, stash)
	stash -= min(8, stash)
	if candiesGiven >= k:
		print(str(i + 1))
		break
if candiesGiven < k:
	print('-1')


R = lambda : list(map(int, input().split()))
(n, k) = R()
arr = R()
sums = 0
curr = 0
pos = -1
for i in range(n):
	sums += arr[i]
	curr += min(sums, 8)
	sums -= min(sums, 8)
	if curr >= k:
		pos = i + 1
		break
print(pos)


R = lambda : list(map(int, input().split()))
(n, k) = R()
a = R()
s = 0
for i in range(n):
	s += a[i]
	d = min(s, 8)
	s -= d
	k -= d
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


import sys
input = sys.stdin.buffer.readline
import os
from math import *
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
now = 0
i = 0
count = 0
while k > 0 and i < n:
	count += 1
	now += arr[i]
	if now >= 8:
		k -= 8
		now -= 8
	else:
		k -= now
		now = 0
	i += 1
if k > 0:
	print('-1')
else:
	print(count)


i = lambda : [*map(int, input().split())]
(n, k) = i()
a = i()
ans = 0
total = 0
remain = 0
for i in a:
	total += min(8, remain + i)
	remain = max(0, remain + i - 8)
	ans += 1
	if total >= k:
		print(ans)
		quit()
print(-1)


(n, amount) = map(int, input().split())
candy = list(map(int, input().split()))
total = 0
minimum = 0
leftOvers = 0
for i in range(n):
	if candy[i] + leftOvers > 8:
		total += 8
		leftOvers += candy[i] - 8
	else:
		total += candy[i] + leftOvers
		leftOvers -= leftOvers
	if total >= amount:
		minimum = i + 1
		break
if minimum == 0:
	print(-1)
else:
	print(minimum)


import decimal
D = decimal.Decimal
l1 = [int(x) for x in input().split()]
n = l1[0]
k = l1[1]
l2 = [int(x) for x in input().split()]
stock = 0
total = 0
ans = 0
for x in l2:
	if total < k:
		if x > 8:
			stock += x - 8
			total += 8
			ans += 1
		elif stock + x >= 8:
			stock -= 8 - x
			total += 8
			ans += 1
		else:
			total += stock + x
			stock = 0
			ans += 1
	else:
		break
if total >= k:
	print(ans)
else:
	print(-1)


(N, K) = map(int, input().split())
a = [int(i) for i in input().split()]
store = 0
s = 0
for day in range(N):
	store += a[day]
	x = min(8, store)
	s += x
	store -= x
	if s >= K:
		break
if s >= K:
	print(day + 1)
else:
	print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
s = 0
sn = 0
ans = 0
for i in range(n):
	sn += arr[i]
	ans += 1
	s += min(8, sn)
	if s >= k:
		print(ans)
		exit(0)
	sn -= min(8, sn)
if s >= k:
	print(ans)
	exit(0)
print(-1)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def main():
	(n, k) = ria()
	a = ria()
	ans = 0
	for i in range(n):
		x = min(8, a[i])
		ans += x
		if i < n - 1:
			a[i + 1] += a[i] - x
		if ans >= k:
			wi(i + 1)
			return
	wi(-1)
main()


first_list = input()
second_line = input()
(n, target) = first_list.split(' ')
(n, target) = (int(n), int(target))
target_ach = 0
next_avail = 0
for ai in second_line.split(' '):
	ai = int(ai)
	target_ach += 1
	ai += next_avail
	if ai <= 8:
		target -= ai
		next_avail = 0
	else:
		target -= 8
		next_avail = ai - 8
	if target <= 0:
		print(target_ach)
		break
else:
	print('-1')


import sys

def solve(arr, k):
	stock = 0
	bran = 0
	for (i, a) in enumerate(arr):
		if bran >= k:
			return i
		stock += a
		give = min(8, stock)
		bran += give
		stock -= give
	if bran >= k:
		return i + 1
	else:
		return -1
inputs = []
for line in sys.stdin:
	inputs.append(line.strip())
(n, k) = map(int, inputs[0].split())
arr = map(int, inputs[1].split())
answer = solve(arr, k)
sys.stdout.write('{}\n'.format(answer))


import sys
(n, k) = map(int, str(input()).split(' '))
ink = list(map(int, str(input()).split(' ')))
sumsweet = sum(ink)
if sumsweet < k:
	print(-1)
else:
	current_sw = 0
	rest2gift = k
	currentgift = 0
	for i in range(0, n):
		current_sw = current_sw + ink[i]
		currentgift = min(8, current_sw)
		current_sw = current_sw - currentgift
		rest2gift = rest2gift - currentgift
		if rest2gift <= 0:
			print(i + 1)
			sys.exit()
	if rest2gift > 0:
		print(-1)


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
num = 0
num2 = 0
ans = 0
for i in range(n):
	num2 += ai[i]
	num += min(8, num2 - num)
	ans += 1
	if num >= k:
		break
if num < k:
	ans = -1
print(ans)


(n, k) = map(int, input().split())
a = [int(a) for a in input().split()]
arya = bran = day = 0
for i in a:
	arya += i
	if arya <= 8:
		bran += arya
		arya = 0
		day += 1
	else:
		bran += 8
		arya -= 8
		day += 1
	if bran >= k:
		print(day)
		exit()
print(-1)


(x, y) = map(int, input().split())
z = list(map(int, input().split()))
days = 0
a = 0
for i in range(x):
	z[i] += a
	a = 0
	if y <= 0:
		break
	if z[i] < 9:
		y -= z[i] + a
		days += 1
	elif z[i] > 8:
		y -= 8
		a = z[i] - 8
		days += 1
if y <= 0:
	print(days)
else:
	print('-1')


(n, k) = [int(i) for i in input().split()]
candies = [int(i) for i in input().split()]
day = 0
arya_candies = 0
status = False
if k - 8 * len(candies) > 0:
	print(-1)
else:
	while k > 0:
		if day == len(candies):
			print(-1)
			status = True
			break
		arya_candies += candies[day]
		temp = min(arya_candies, 8)
		k -= temp
		arya_candies -= temp
		day += 1
	if status is False:
		print(day)


(n, k) = list(map(int, input().split()))
A = list(map(int, input().split()))
arya = 0
bran = 0
for (i, a) in enumerate(A):
	arya += a
	bran += min(arya, 8)
	arya -= min(arya, 8)
	if bran >= k:
		print(i + 1)
		return
print(-1)


(n, k) = input().split()
n = int(n)
k = int(k)
arr = [0] * n
arr = input().split()
for i in range(len(arr)):
	arr[i] = int(arr[i])
extra = 0
given = 0
count = 0
for i in range(n):
	arr[i] = arr[i] + extra
	extra = 0
	if arr[i] > 8:
		extra = extra + arr[i] - 8
		arr[i] = 8
	given = given + arr[i]
	if given > k or given == k:
		break
	else:
		count += 1
if given < k:
	print(-1)
else:
	print(count + 1)


import sys
(n, k) = [int(x) for x in input().split()]
arr = list(map(int, input().split()))
arya = 0
bran = 0
cnt = 0
for a in arr:
	arya = arya + a
	bran = bran + min(arya, 8)
	arya = arya - min(arya, 8)
	cnt = cnt + 1
	if bran >= k:
		print(cnt)
		sys.exit(0)
print(-1)


(n, k) = input().split()
n = int(n)
k = int(k)
days = [int(i) for i in input().split()]
bran = 0
arya = 0
for x in range(0, n):
	arya += days[x]
	if arya >= 8:
		arya -= 8
		bran += 8
	else:
		bran += arya
		arya = 0
	if bran >= k:
		print(x + 1)
		exit()
print(-1)


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
days = 0
count = 0
acc = 0
for day in ai:
	acc += day
	if acc >= 8:
		count += 8
		acc -= 8
	else:
		count += acc
		acc = 0
	days += 1
	if count >= k:
		break
if count >= k:
	print(days)
else:
	print(-1)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
i = 0
candy = 0
while k > 0 and i < n:
	candy += s[i]
	p = min(candy, 8)
	k -= p
	i += 1
	candy -= p
if k > 0:
	print(-1)
	exit()
print(i)


def main():
	(N, K) = map(int, input().split())
	A = tuple(map(int, input().split()))
	candies = 0
	give = K
	i = 0
	while i < N:
		if A[i] + candies >= 8:
			give -= 8
			candies += A[i] - 8
		else:
			give -= A[i] + candies
			candies = 0
		if give <= 0:
			ans = i + 1
			break
		i += 1
	else:
		ans = -1
	print(ans)
main()


(n, k) = input().split()
(n, k) = (int(n), int(k))
a = input().split()
aLength = len(a)
breakCode = False
candiesLeft = 0
candiesGiven = 0
breakCode = False

def BranSatisfied():
	if candiesGiven >= k:
		print(i + 1)
		breakCode = True
		exit()
	if candiesGiven < k and i + 1 == aLength:
		print(-1)
		breakCode = True
		exit()
for i in range(n):
	candiesLeft += int(a[i])
	if candiesLeft < 8:
		candiesGiven += candiesLeft
		candiesLeft = 0
		BranSatisfied()
		if breakCode == True:
			exit()
	else:
		candiesGiven += 8
		candiesLeft -= 8
		BranSatisfied()
		if breakCode == True:
			exit()


(n, k) = map(int, input().split())
res = 0
pre = 0
a = list(map(int, input().split()))
for x in a:
	if k:
		d = min(8, pre + x)
		k = max(0, k - d)
		res += 1
		pre = x + pre - d
print(res if not k else -1)


(n, k) = map(int, input().split())
lst = map(int, input().split())
count = 0
cur = 0
for i in lst:
	i += cur
	k -= min(i, 8)
	count += 1
	cur = i - min(i, 8)
	if k <= 0:
		print(count)
		exit()
print('-1')


in1 = input().split()
n = int(in1[0])
k = int(in1[1])
sum = 0
ans = 0
d = 0
for c in input().split():
	ans += 1
	sum += min(int(c), 8)
	if int(c) > 8:
		d += int(c) - 8
	if int(c) < 8:
		sum += min(d, 8 - int(c))
		d -= min(d, 8 - int(c))
	if sum >= k:
		print(ans)
		break
if sum < k:
	print(-1)


(n, k) = list(map(int, input().split()))
candies = list(map(int, input().split()))
days = 0
buff = 0
b = False
for (i, e) in enumerate(candies):
	if e < 9:
		if buff:
			if buff + e < 9:
				k -= e + buff
				buff = 0
			else:
				k -= 8
				buff -= 8 - e
		else:
			k -= e
	else:
		k -= 8
		buff += e - 8
	if k <= 0:
		print(i + 1)
		b = True
		break
if not b:
	print(-1)


def list_input():
	return list(map(int, input().split()))

def map_input():
	return map(int, input().split())

def map_string():
	return input().split()
(n, k) = map_input()
a = list_input()
cur = 0
cnt = 1
for i in a:
	cur += i
	if cur >= 8:
		cur -= 8
		k -= 8
	else:
		k -= cur
		cur = 0
	if k <= 0:
		break
	cnt += 1
if k <= 0:
	print(cnt)
else:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
s = 0
ans = -1
for i in range(n):
	s += l[i]
	k -= min(8, s)
	s -= min(8, s)
	if k <= 0:
		ans = i + 1
		break
print(ans)


read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
total = 0
rest = 0
for i in range(n):
	rest += a[i]
	give = min(8, rest)
	total += give
	rest -= give
	if total >= k:
		print(i + 1)
		exit()
print(-1)


(n, k) = (*map(int, input().split()),)
days = [*map(int, input().split())]
res = 0
next_day_candies = 0
for i in days:
	res += 1
	if i >= 8:
		k -= 8
		next_day_candies += i - 8
	elif next_day_candies >= 8:
		next_day_candies -= 8
		k -= 8
		next_day_candies += i
	elif next_day_candies > 0:
		next_day_candies += i
		if next_day_candies >= 8:
			next_day_candies -= 8
			k -= 8
		else:
			k -= next_day_candies
			next_day_candies = 0
	elif i > 0:
		k -= i
	if k <= 0:
		print(res)
		break
else:
	print(-1)


(n, m) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
i = 0
while i < n and m > 0:
	m = m - min(8, l[i])
	if l[i] > 8 and i < n - 1:
		l[i + 1] += l[i] - 8
	i += 1
ans = i
if m > 0:
	ans = -1
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
s = 0
kk = 0
for f in range(n):
	if l[f] >= 8:
		ans += 1
		s += l[f] - 8
		kk += 8
	elif l[f] + s >= 8:
		ans += 1
		kk += 8
		s -= 8 + l[f]
	else:
		ans += 1
		kk += l[f] + s
		s = 0
	if kk >= k:
		print(ans)
		break
	if f == n - 1:
		print(-1)
		break


(n, k) = input().split(' ')
(n, k) = (int(n), int(k))
a = list(map(lambda x: int(x), input().split(' ')))
mg = 8
count = 1
csum = 0
for i in range(n):
	csum = csum + a[i]
	k = k - min(mg, csum)
	csum = csum - min(mg, csum)
	if k > 0:
		count += 1
	else:
		break
if k > 0:
	print(-1)
else:
	print(count)


(n, k) = map(int, input().split())
sweets = tuple(map(int, input().split()))
sumS = 0
days = 0
extra = 0
for sweet in sweets:
	if sumS < k:
		if sweet + extra <= 8:
			sumS += min(8, sweet + extra)
			extra = max(sweet + extra - 8, 0)
		else:
			sumS += 8
			extra = max(sweet + extra - 8, 0)
		days += 1
	else:
		break
if sumS >= k:
	print(days)
else:
	print(-1)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
tot = 0
remain = 0
i = 0
while i < n:
	if a[i] + remain <= 8:
		tot += a[i] + remain
		remain = 0
	else:
		tot += 8
		remain += a[i] - 8
	if tot >= k:
		print(i + 1)
		break
	i += 1
if i == n:
	print(-1)


(n, k) = [int(i) for i in input().split()]
lst = list(map(int, input().split()))
(s, c) = (0, 0)
for i in range(n):
	if lst[i] > 8:
		s += 8
		c += 1
		try:
			lst[i + 1] += lst[i] - 8
		except:
			pass
	elif lst[i] <= 8:
		s += lst[i]
		c += 1
	if s >= k:
		break
if c != 0 and s >= k:
	print(c)
else:
	print(-1)


import sys
read = lambda : sys.stdin.readline().rstrip()
readi = lambda : int(sys.stdin.readline())
writeln = lambda x: sys.stdout.write(str(x) + '\n')
write = lambda x: sys.stdout.write(x)
(N, K) = map(int, read().split())
ns = list(map(int, read().split()))
(A, B) = (0, 0)
ans = -1
for i in range(N):
	A += ns[i]
	if A >= 8:
		A -= 8
		B += 8
	else:
		B += A
		A = 0
	if B >= K:
		ans = i + 1
		break
writeln(ans)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
arya = 0
bran = 0
day = 0
for i in a:
	arya += i
	if arya > 8:
		bran += 8
		arya -= 8
		day += 1
	elif arya == 8:
		bran += 8
		arya -= 8
		day += 1
	elif arya < 8:
		bran += arya
		arya = 0
		day += 1
	if bran >= k:
		print(day)
		break
else:
	print(-1)


tmp = input().split()
n = int(tmp[0])
k = int(tmp[1])
a = input().split()
for i in range(n):
	a[i] = int(a[i])
sum = 0
cnt = 0
i = 0
while cnt < k and i < n:
	sum += a[i]
	if sum >= 8:
		sum -= 8
		cnt += 8
	else:
		cnt += sum
		sum = 0
	i += 1
if cnt < k:
	print(-1)
else:
	print(i)


from sys import maxsize, stdout, stdin, stderr
mod = int(1000000000.0 + 7)
import re

def tup():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())

def lint():
	return [int(x) for x in stdin.readline().split()]

def S():
	return input().strip()

def grid(r, c):
	return [lint() for i in range(r)]

def debug(*args, c=6):
	print('\x1b[3{}m'.format(c), *args, '\x1b[0m', file=stderr)
from math import log2, sqrt
from collections import defaultdict
(n, k) = tup()
ls = lint()
s = 0
c = 0
f = False
idx = -1
for i in range(n):
	s += ls[i]
	if s < 8:
		c += s
		s = 0
	else:
		c += 8
		s -= 8
	if c >= k:
		f = True
		idx = i + 1
		break
print(idx)


(n, candy) = [int(i) for i in input().split()]
days = [int(i) for i in input().split()]
daysNeed = 0
kolb = 0
kola = 0
while kolb < candy and daysNeed < n:
	kola += days[daysNeed]
	a = min(8, kola)
	kola -= a
	kolb += a
	daysNeed += 1
if kolb < candy:
	print(-1)
else:
	print(daysNeed)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
x = 0
y = 0
z = 0
b = 0
for i in a:
	b += 1
	x += i
	if x >= 8:
		y += 8
	else:
		y += x
	x -= 8
	if x < 0:
		x = 0
	if y >= k:
		z = i
		break
if z == 0:
	print(-1)
else:
	print(b)


(n, k) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
(tot, now) = (0, 0)
for i in range(n):
	tot += a[i]
	now += min(8, tot)
	tot -= min(8, tot)
	if now >= k:
		print(i + 1)
		break
else:
	print(-1)


candies = 0
days = 0
o = 0
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for amoung in a:
	candies += amoung
	k -= min(candies, 8)
	candies -= min(candies, 8)
	days += 1
	if k <= 0:
		print(days)
		o = 1
		break
if o == 0:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
summ = 0
for j in range(n):
	summ += a[j]
if n * 8 >= k and k <= summ:
	carramel = 0
	for i in range(n):
		carramel += a[i]
		if carramel > 8:
			k -= 8
			carramel -= 8
		else:
			k -= carramel
			carramel = 0
		if k <= 0:
			days = i + 1
			print(days)
			break
	if k > 0:
		print('-1')
else:
	print('-1')


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
count = t = 0
for i in range(len(arr)):
	if k <= 0:
		break
	else:
		t += arr[i]
		k -= min(8, t)
		t -= min(8, t)
		count += 1
if k > 0:
	print(-1)
else:
	print(count)


max_days = 0
req_candies = 0
candies_each_day = 0
while True:
	q1 = input()
	max_days = int(q1.split()[0])
	req_candies = int(q1.split()[1])
	q2 = input()
	candies_each_day = q2.split()
	if len(candies_each_day) != max_days:
		print("candies each day don't match max number of days given above\n")
		print('try again\n')
	else:
		break
didnt_work = True
bran_candies = 0
saved_up = 0
for x in range(0, max_days):
	todays_pool = int(candies_each_day[x]) + saved_up
	if todays_pool >= 8:
		bran_candies += 8
		saved_up = todays_pool - 8
	else:
		bran_candies += todays_pool
		saved_up = 0
	if bran_candies >= req_candies:
		didnt_work = False
		print(x + 1)
		break
if didnt_work:
	print(-1)


d = input().split(' ')
f = input().split(' ')
summ = 0
total = 0
o = 0
for i in range(int(d[0])):
	total = total + int(f[i])
	if total < 8:
		summ = summ + total
		total = 0
	else:
		summ = summ + 8
		total = total - 8
	if int(d[1]) <= summ:
		o = 1
		print(i + 1)
		break
if o == 0:
	print(-1)


(n, k) = map(int, input().split())
x = map(int, input().split())
saved = 0
count = 0
index = 1
for i in x:
	if i > 8:
		count += 8
		saved += i - 8
	elif i + saved >= 8:
		count += 8
		saved -= 8 - i
	else:
		count += i + saved
		saved = 0
	if count >= k:
		print(index)
		break
	index += 1
if count < k:
	print(-1)


A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
summary = 0
temp = 0
for i in range(A[0]):
	temp = temp + B[i]
	if temp - summary < 8:
		summary = summary + (temp - summary)
	else:
		summary = summary + 8
	if summary >= A[1]:
		print(i + 1)
		break
if summary < A[1]:
	print(-1)


(n, k) = input().split()
candies = list(input().split())
arya = 0
bran = 0
flag = -1
for (i, x) in enumerate(candies):
	arya += int(x)
	if arya > 8:
		arya -= 8
		bran += 8
	else:
		bran += arya
		arya = 0
	if bran >= int(k):
		flag = i + 1
		break
print(flag)


(n, k) = map(int, input().split())
box = []
given = 0
days = 0
saved = 0
temp = input().split()
for i in range(n):
	m = min(8, int(temp[i]) + saved)
	given += m
	if int(temp[i]) < 8 and saved > 0:
		saved -= m - int(temp[i])
	saved += max(0, int(temp[i]) - m)
	days += 1
	if given >= k:
		print(days)
		break
else:
	print(-1)


(n, k) = [int(el) for el in input().split()]
A = [int(el) for el in input().split()]
cur = 0
for (i, a) in enumerate(A):
	cur += a
	temp = min(cur, 8)
	k -= temp
	cur -= temp
	if k <= 0:
		break
if k <= 0:
	print(i + 1)
else:
	print(-1)


def days_for_candies(n, k, a):
	candy_lasts = k
	current = 0
	for (i, candys) in enumerate(a):
		current += candys
		candys_to_give = min(current, 8)
		candy_lasts -= candys_to_give
		current -= candys_to_give
		if candy_lasts <= 0:
			return i + 1
	return -1

def main():

	def list_from_input():
		return list(map(int, input().split()))
	(n, k) = list_from_input()
	a = list_from_input()
	print(days_for_candies(n, k, a))
main()


def main():
	(N, K) = map(int, input().split())
	nums = list(map(int, input().split()))
	aran = 0
	bran = 0
	for n in range(N):
		aran += nums[n]
		x = min(aran, 8)
		aran -= x
		bran += x
		if bran >= K:
			print(n + 1)
			return
	print(-1)
	return
main()


s = input().split()
n = int(s[0])
k = int(s[1])
s = input().split()
t = 0
l = []
while t < n:
	l.append(int(s[t]))
	t += 1
box = 0
c = 0
i = 0
while c < k:
	box += l[i]
	if box >= 8:
		box -= 8
		c += 8
	else:
		c += box
		box = 0
	i += 1
	if i == n:
		break
if i <= n and c >= k:
	print(i)
else:
	print('-1')


import sys
import math
import bisect
import itertools
import random
import re

def main():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	val = 0
	tmp = 0
	ans = -1
	for i in range(n):
		tmp += A[i]
		if tmp >= 8:
			tmp -= 8
			val += 8
		else:
			val += tmp
			tmp = 0
		if val >= m:
			ans = i + 1
			break
	print(ans)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	(n, k) = LI()
	a = LI()
	b = 0
	c = 0
	for i in range(n):
		b += a[i]
		t = min(8, b)
		c += t
		b -= t
		if c >= k:
			return i + 1
	return -1
print(main())


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(n, k) = M()
l = L()
g = 0
f = 0
s = 0
for i in range(n):
	s += l[i]
	d = min(8, s)
	g += d
	s -= d
	if g >= k:
		print(i + 1)
		f = 1
		break
if f == 0:
	print(-1)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 0
tmp = 0
tmp2 = 0
ok = False
for i in range(len(a)):
	if a[i] >= 8:
		tmp2 += a[i] - 8
		tmp += 8
		ans += 1
	elif a[i] + tmp2 >= 8:
		tmp += 8
		ans += 1
		tmp2 -= 8 - a[i]
	else:
		tmp += a[i]
		tmp += tmp2
		ans += 1
		tmp2 = 0
	if tmp >= k:
		ok = True
		break
if ok:
	print(ans)
else:
	print(-1)


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
left = int(0)
su = int(0)
done = False
for i in range(len(arr)):
	left += arr[i]
	if left >= 8:
		su += 8
		left -= 8
	else:
		su += left
		left = 0
	if su >= k:
		done = True
		print(i + 1)
		break
if not done:
	print('-1')


(N, K) = list(map(int, input().split()))
days = list(map(int, input().split()))
pocket = 0
day = 0
give = 0
for x in days:
	if K <= 0:
		break
	if x <= 8:
		give = x
		if pocket > 0:
			if pocket >= 8 - x:
				pocket -= 8 - x
				give = 8
			else:
				give = x + pocket
				pocket = 0
	elif x > 8:
		give = 8
		pocket += x - give
	K -= give
	day += 1
if K > 0:
	print(-1)
else:
	print(day)


(n, k) = map(int, input().split())
candies = list(map(int, input().split()))
(day, have) = (0, 0)
candies.append(0)
for ind in range(n):
	day += 1
	if candies[ind] >= 8:
		have += 8
		candies[ind + 1] += candies[ind] - 8
	else:
		have += candies[ind]
	if have >= k:
		break
if day == n and have < k:
	day = -1
print(day)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
count = 0
f = 0
for i in range(n):
	if a[i] <= 8:
		count += a[i]
	else:
		count += 8
		try:
			a[i + 1] = a[i + 1] + (a[i] - 8)
		except:
			pass
	if count >= k:
		print(i + 1)
		f = 1
		break
if f == 0:
	print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
sister = 0
brother = 0
for day in range(n):
	sister += arr[day]
	if k <= 8:
		if sister >= k:
			print(day + 1)
			exit()
	else:
		giving = min(8, sister)
		brother += giving
		sister -= giving
		if brother >= k:
			print(day + 1)
			exit()
print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
summa = 0
ans = 0
cur = 0
if s < k:
	print(-1)
	exit()
for (index, i) in enumerate(a):
	if i >= 8:
		cur += 8
		summa += i - 8
		ans += 1
	elif summa <= 8 - i:
		cur += i + summa
		summa = 0
		ans += 1
	else:
		cur += 8
		summa -= 8 - i
		ans += 1
	if cur >= k:
		break
if cur < k:
	print(-1)
	exit()
print(ans)


def check(n, k, arr):
	sum1 = 0
	for i in range(n - 1):
		sum1 += min(arr[i], 8)
		if arr[i] > 8:
			left = arr[i] - 8
			arr[i + 1] += left
		if sum1 >= k:
			return i + 1
	if sum1 + min(arr[n - 1], 8) >= k:
		return n
	else:
		return -1
inp1 = list(map(int, input().strip().split()))[:2]
(n, k) = (inp1[0], inp1[1])
arr = list(map(int, input().strip().split()))[:n]
l = check(n, k, arr)
print(l)


import sys

def r():
	return list(map(int, input().split()))
(n, k) = list(map(int, input().split()))
a = r()
sum = 0
cnt = 0
for i in range(n):
	sum += a[i]
	cnt += min(8, sum)
	sum = max(0, sum - 8)
	if cnt >= k:
		print(i + 1)
		return
print(-1)


(n1, n2) = map(int, input().split())
candy = list(map(int, input().split(' ')))
arya = 0
day = 0
bran = 0
flag = False
for x in candy:
	arya = arya + x
	day = day + 1
	if arya >= 8:
		arya = arya - 8
		bran = bran + 8
		if bran >= n2:
			print(day)
			flag = True
			break
	else:
		bran = bran + arya
		arya = 0
		if bran >= n2:
			print(day)
			flag = True
			break
if not flag:
	print(-1)


def solve():
	sweets = 0
	brans_sweets = 0
	for i in range(n):
		sweets += costs[i]
		if sweets >= 8:
			sweets -= 8
			brans_sweets += 8
		else:
			brans_sweets += sweets
			sweets = 0
		if brans_sweets >= need:
			print(i + 1)
			exit(0)
	print(-1)
(n, need) = map(int, input().split())
costs = list(map(int, input().split()))
solve()


(n, k) = (int(a) for a in input('').split())
store = 0
given = 0
candies = [int(a) for a in input('').split()]
i = 0
for i in range(0, n):
	if candies[i] < 8:
		x = 8 - candies[i]
		if store <= x:
			given += store
			store = 0
		else:
			given += x
			store -= x
		given += candies[i]
	else:
		x = candies[i] - 8
		given += 8
		store += x
	if given >= k:
		break
if i == n - 1 and given < k:
	print(-1)
else:
	print(i + 1)


(n, k) = map(int, input().split())
c = 0
d = 0
flag = 0
ost = 0
l = list(map(int, input().split()))
for i in l:
	if i <= 8:
		y = 0
		if ost != 0:
			y = 8 - i
			if ost < y:
				y = ost
		c += i + y
		d += 1
		ost -= y
	else:
		x = abs(i - 8)
		c += i - x
		ost += x
		d += 1
	if c >= k:
		print(d)
		flag = 1
		break
if flag == 0:
	print(-1)


import sys
(n, k) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
d = 0
tmp = 0
r = 0
for i in a:
	tmp += min(r + i, 8)
	d += 1
	if tmp >= k:
		print(d)
		sys.exit()
	r = max(r + i - 8, 0)
print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
from math import ceil
s = 0
flag = 0
for i in range(n):
	if s >= k:
		flag = 1
		break
	if l[i] > 8:
		s = s + 8
		if i < n - 1:
			l[i + 1] = l[i + 1] + l[i] - 8
	else:
		s = s + l[i]
if s >= k:
	if flag == 1:
		print(i)
	else:
		print(i + 1)
else:
	print(-1)


str1 = input()
n = int(str1.split()[0])
k = int(str1.split()[1])
rem = 0
ans = -1
ct = 0
str2 = input()
vallist = str2.split()
for x in range(n):
	val = int(vallist[x])
	ct += min(8, rem + val)
	rem += val - min(8, rem + val)
	if ct >= k and ans == -1:
		ans = x + 1
print(ans)


def solve():
	(n, k) = map(int, input().split())
	A = map(int, input().split())
	s = 0
	i = 1
	for a in A:
		s += a
		t = min(8, s)
		s -= t
		k -= t
		if k <= 0:
			return i
		i += 1
	return -1
print(solve())


def main():
	[n, k] = [int(_) for _ in input().split()]
	candies = [int(_) for _ in input().split()]
	day = 0
	given_candies = 0
	saved_candies = 0
	while day < n and given_candies < k:
		today_candies = saved_candies + candies[day]
		if today_candies <= 8:
			given_candies += today_candies
			saved_candies = 0
		else:
			given_candies += 8
			saved_candies = today_candies - 8
		day += 1
	print(-1 if given_candies < k else day)
main()


from math import ceil
(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
cur = 0
ans = 0
for i in range(n):
	cur += a[i]
	r = min(8, cur)
	k -= r
	cur -= r
	ans += 1
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(ans)


(n, k) = map(int, input().split())
list_candies = list(map(int, input().split()))
(i, r) = (0, 0)
for c in list_candies:
	r += c
	i += 1
	k -= min(8, r)
	r -= min(8, r)
	if k <= 0:
		print(i)
		quit()
print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
total = sum(a)
cnt = 0
d = 0
l = 0
for i in range(n):
	if a[i] > 8:
		cnt += 8
		l += a[i] - 8
	elif l > 8:
		cnt += 8
		l -= 8
	elif l + a[i] > 8:
		cnt += 8
		l = l + a[i] - 8
	else:
		cnt += l + a[i]
		l = 0
	d += 1
	if cnt >= k:
		exit(print(d))
print(-1)


(n, k) = map(int, input().split())
cnt = 0
j = 0
arr = list(map(int, input().split()))
arr.append(0)
for i in range(0, n):
	if arr[i] > 8:
		arr[i + 1] += arr[i] - 8
		arr[i] = 8
for i in range(0, n):
	cnt += arr[i]
	j = i
	if cnt >= k:
		break
if cnt >= k:
	print(j + 1)
else:
	print(-1)


(n, k) = [int(i) for i in input().split()]
a = [int(k) for k in input().split()]
days = 0
candies = 0
stored = 0
for j in a:
	stored += j
	if stored <= 8:
		candies += stored
		stored = 0
	else:
		candies += 8
		stored -= 8
	days += 1
	if candies < k:
		if days == n:
			print(-1)
			break
	else:
		print(days)
		break


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
count = 0
(ana, f) = (0, 0)
ans = 0
for val in a:
	if ans >= k:
		f = 1
		break
	if val + ana <= 8:
		ans += val + ana
		ana = 0
		count += 1
	else:
		ana = val + ana - 8
		count += 1
		ans += 8
if f == 1 or ans >= k:
	print(count)
else:
	print(-1)


days_and_wants = input().split()
Days = days_and_wants[0]
wants = days_and_wants[1]
Bcandies = 0
Acandies = 0
days = 0
candies_per_day = input().split()
for i in candies_per_day:
	Acandies += int(i)
	if Acandies <= 8:
		Bcandies += Acandies
		Acandies = 0
	else:
		Bcandies += 8
		Acandies -= 8
	days += 1
	if Bcandies >= int(wants):
		break
if Bcandies < int(wants):
	print(-1)
else:
	print(days)


(nb_days, candies) = [int(x) for x in input().split()]
candy_days = [int(x) for x in input().split()]
days = 0
candy = 0
ans = -1
for (i, c) in enumerate(candy_days):
	candy += c
	done = min(8, candy)
	candy -= done
	candies -= done
	if candies <= 0:
		ans = i + 1
		break
print(ans)


(n, k) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
for i in range(len(arr) - 1):
	k -= min(8, arr[i])
	arr[i] -= min(8, arr[i])
	arr[i + 1] += max(0, arr[i])
	if k <= 0:
		ans = i + 1
		break
if k > 0:
	if k - min(8, arr[-1]) <= 0:
		print(n)
	else:
		print(-1)
else:
	print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(a1, a2) = (0, 0)
ans = False
for i in range(n):
	a1 += a[i]
	a2 += min(8, a1)
	a1 -= min(8, a1)
	if a2 >= k:
		ans = i + 1
		break
if ans:
	print(ans)
else:
	print(-1)


import sys
lines = [line.strip() for line in sys.stdin.readlines()]
(n, k) = [int(x) for x in lines[0].split()]
days = [int(x) for x in lines[1].split()]
arya = 0
bran = 0
cont = 0
for i in range(len(days)):
	arya += days[i]
	x = min(arya, 8)
	arya -= x
	bran += x
	cont += 1
	if bran >= k:
		break
if bran >= k:
	print(cont)
else:
	print(-1)


(n, m) = input().split()
(n, m) = (int(n), int(m))
f = input().split()
f = [int(i) for i in f]
if m > n * 8:
	print(-1)
elif m > sum(f):
	print(-1)
elif m == sum(f):
	print(n)
else:
	count = 0
	while m > 0:
		if count >= n - 1:
			f.append(0)
		m -= min(8, f[count])
		if min(8, f[count]) == 8:
			f[count + 1] += f[count] - 8
		count += 1
	if count > n:
		print(-1)
	else:
		print(count)


line = list(map(int, input().split()))
n = line[0]
k = line[1]
a = list(map(int, input().split()))
res = -1
for (i, elem) in enumerate(a):
	if elem < 8:
		k -= elem
	else:
		if i < n - 1:
			a[i + 1] += elem - 8
		k -= 8
	if k <= 0:
		res = i + 1
		break
print(res)


inp_lst = input().split()
n = int(inp_lst[0])
k = int(inp_lst[1])
str_lst = input().split()
lst = [int(i) for i in str_lst]
find = 0
give = 0
hasPrint = False
for i in range(len(lst)):
	find += lst[i]
	if find > 8:
		find -= 8
		give += 8
	else:
		give += find
		find = 0
	if give >= k:
		print(i + 1)
		hasPrint = True
		break
if not hasPrint:
	print(-1)


import sys
(n, k) = map(int, input().split())
candy = map(int, input().split())
es = 0
for (i, can) in enumerate(candy):
	es += can
	if es > 8:
		k -= 8
		es -= 8
	else:
		k -= es
		es = 0
	if k <= 0:
		print(i + 1)
		sys.exit()
print(-1)


aria = 0
bran = 0
day = 0
x = 8
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k // n > 8 or (k // n == 8 and k % n != 0):
	print(-1)
	exit(0)
for i in range(n):
	x = 8
	day += 1
	new_bran = bran
	aria += a[i]
	while bran == new_bran:
		if aria >= x:
			bran += x
			aria -= x
		else:
			x -= 1
	if bran >= k:
		print(day)
		exit(0)
if bran < k:
	print(-1)
	exit(0)


(n, k) = map(int, input().split())
l = [int(x) for x in input().split()]
c = 0
for i in range(n):
	if l[i] > 8:
		c += 8
		if i != n - 1:
			l[i + 1] += l[i] - 8
	else:
		c += l[i]
	if c >= k:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
candy = 0
other = 0
days = 0
while candy < k and days < n:
	if arr[days] >= 8:
		candy = candy + 8
		other = other + arr[days] - 8
	elif other >= 8:
		candy = candy + 8
		other = other - 8 + arr[days]
	else:
		other = other + arr[days]
		if other >= 8:
			candy = candy + 8
			other = other - 8
		else:
			candy = candy + other
			other = 0
	days += 1
if candy >= k:
	print(days)
else:
	print(-1)


(n, k) = map(int, input().split())
x = [int(x) for x in input().split()]
x.append(0)
t = 0
i = 0
d = 0
while 1:
	if x[i] > 8:
		x[i + 1] = x[i + 1] + (x[i] - 8)
		x[i] = 8
	t += x[i]
	if t >= k:
		print(i + 1)
		break
	if t < k:
		i += 1
	if i >= n:
		print('-1')
		exit()


nk = list(map(int, input().split()))
a = list(map(int, input().split()))
bank = 0
for i in range(nk[0]):
	bank += a[i]
	nk[1] -= min(bank, 8)
	bank -= min(bank, 8)
	if nk[1] <= 0:
		break
if nk[1] > 0:
	print(-1)
else:
	print(i + 1)


(n, k) = input().split()
(n, k) = (int(n), int(k))
a = [int(x) for x in input().split(' ')]
carry = 0
sum = 0
i = 0
while sum < k and i < n:
	if a[i] + carry <= 8:
		sum += a[i] + carry
		carry = 0
	else:
		sum += 8
		carry += a[i] - 8
	i += 1
if sum < k:
	i = -1
print(i)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
remain = 0
printed = False
sumi = 0
for x in range(n):
	arr[x] += remain
	if arr[x] > 8:
		remain = arr[x] - 8
		sumi += 8
	else:
		sumi += arr[x]
		remain = 0
	if sumi >= k:
		print(x + 1)
		printed = True
		break
if not printed:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(i, A, B) = (0, 0, 0)
flag = False
while i < n:
	A += a[i]
	B += min(8, A)
	A = max(A - 8, 0)
	i += 1
	if B >= k:
		flag = True
		break
if flag:
	print(i)
else:
	print(-1)


import math
q = lambda : [int(f) for f in input().split()]
(n, k) = q()
a = q()
i = 0
r = 0
m = 0
for x in range(n):
	a[x] += r
	r = 0
	m += min(8, a[x])
	if a[x] > 8:
		r += a[x] - 8
	i += 1
	if m >= k:
		print(i)
		exit()
else:
	print('-1')


(n, k) = [int(s) for s in input().split()]
arr = [int(s) for s in input().split()]
counter = 0
rest = 0
i = 0
while arr[len(arr) - 1] > 0 or k > 0:
	if k > 0:
		if arr[i] <= 8:
			k -= arr[i]
		else:
			k -= 8
			if i == len(arr) - 1:
				arr.append(0)
			arr[i + 1] += arr[i] - 8
		counter += 1
		i += 1
		if len(arr) == i:
			break
	else:
		break
if counter <= n and k <= 0:
	print(counter)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
Day = Candies = 0
for i in range(n):
	Candies += a[i]
	if Candies <= 8:
		k -= Candies
		Candies = 0
	else:
		Candies -= 8
		k -= 8
	Day += 1
	if k <= 0:
		break
print(Day if k <= 0 else -1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
tmp = 0
counter = 0
s = 0
for i in a:
	counter += 1
	s += i
	if s >= 8:
		s -= 8
		tmp += 8
	else:
		tmp += s
		s = 0
	if tmp >= k:
		print(counter)
		exit()
print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))

def main():
	amount = 0
	s = 0
	for i in range(n):
		amount += a[i]
		s += min(amount, 8)
		amount -= min(amount, 8)
		if s >= k:
			return i + 1
	return -1
print(main())


def ArianBrain(days, allCandy, parties):
	remaindNumber = 0
	for i in range(0, days):
		remaindNumber += parties[i]
		allCandy -= min(remaindNumber, 8)
		if allCandy <= 0:
			return i + 1
		remaindNumber -= min(remaindNumber, 8)
	return -1
(days, allCandy) = tuple(map(int, input().split(' ')))
parties = list(map(int, input().split(' ')))
print(ArianBrain(days, allCandy, parties))


(n, k) = input().split()
x = input()
a = x.split()
s = 0
i = 0
y = 0
while s < int(k):
	t = int(a[i]) + y
	if t <= 8:
		s = s + t
		y = 0
	else:
		s = s + 8
		y = t - 8
	i = i + 1
	if i == int(n):
		break
if s < int(k):
	print(-1)
else:
	print(i)


read = lambda : map(int, input().split())
(n, k) = read()
a = list(read())
ans = -1
rem = 0
cur = 0
for i in range(n):
	add = min(8, rem + a[i])
	cur += add
	if add == 8:
		rem += a[i] - 8
	else:
		rem = 0
	if cur >= k:
		ans = i + 1
		break
print(ans)


(n, k) = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
d = 0
t = 0
for i in l:
	if t + i <= 8 and t + i >= k:
		print(d + 1)
		break
	elif t + i <= 8:
		d += 1
		t = 0
		k = k - (i + t)
		if k <= 0:
			print(d)
			break
	elif t + i > 8:
		t += i - 8
		k = k - 8
		d += 1
		if k <= 0:
			print(d)
			break
else:
	if k <= 0:
		print(n)
	else:
		print('-1')


split = lambda : list(map(int, input().split()))
(a, b) = split()
candies = split()
p = q = 0
for x in range(a):
	p += candies[x]
	s = min(8, p)
	p -= s
	q += s
	if q >= b:
		print(x + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
candies = input().split()
candies = [int(i) for i in candies]
target = 0
remainder = 0
day = 0
left = 0
while target < k:
	for j in range(len(candies)):
		empty = False
		day += 1
		if candies[j] <= 8:
			target += candies[j]
			left = k - target
			empty = True
			bn = 8 - candies[j]
		elif candies[j] > 8:
			target += 8
			remainder += candies[j] - 8
			left = k - target
		if empty == True and remainder > 0:
			for i in range(bn):
				target += 1
				remainder -= 1
				if remainder == 0:
					break
		if target >= k:
			print(day)
			break
	else:
		print('-1')
	break


(n, k) = map(int, input().split())
a = tuple(map(int, input().split()))
cakeown = 0
cakegive = 0
for i in range(n):
	cakeown += a[i]
	if cakeown <= 8:
		cakegive += cakeown
		cakeown = 0
	else:
		cakegive += 8
		cakeown -= 8
	if cakegive >= k:
		print(i + 1)
		exit(0)
print(-1)


(_, k) = map(int, input().split())
acc = 0
result = -1
for (i, v) in enumerate(map(int, input().split())):
	acc += v
	d = min(acc, 8)
	k -= d
	acc -= d
	if k <= 0:
		result = i + 1
		break
print(result)


(n, k) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
stock = 0
days = 0
for i in range(len(a)):
	if a[i] >= 8:
		k -= 8
		a[i] -= 8
		stock += a[i]
		days += 1
	elif stock + a[i] >= 8:
		stock = stock - 8 + a[i]
		a[i] = 0
		k -= 8
		days += 1
	else:
		k -= a[i] + stock
		stock = 0
		days += 1
	if k <= 0:
		print(days)
		exit()
print('-1')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
remain = 0
sumi = 0
for i in range(n):
	if sumi < k:
		cnt = i
		sumi += min(a[i] + remain, 8)
		remain += a[i] - min(a[i] + remain, 8)
	else:
		break
if sumi < k:
	print(-1)
else:
	print(cnt + 1)


a = [int(nums) for nums in input().split(' ')]
dwc = [int(nums) for nums in input().split()]
n = a[0]
k = a[1]
sa = sum(dwc)
sb = 0
i = 1
while sb < k and i <= n and (sa >= 0):
	d = k - sb
	if dwc[i - 1] > 8 and d > 8:
		sb += 8
		sa -= 8
		try:
			dwc[i] += dwc[i - 1] - 8
		except:
			pass
	elif d > dwc[i - 1]:
		sb += dwc[i - 1]
		sa -= dwc[i - 1]
	elif d <= dwc[i - 1]:
		sb += d
		sa -= d
	i += 1
if sb == k:
	print(i - 1)
else:
	print('-1')


import math
import sys
import collections
from collections import defaultdict
from sys import stdin, stdout
sys.setrecursionlimit(10 ** 9)
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
(cnt, summ) = (0, 0)
i = 0
while k > 0 and i < n:
	summ += arr[i]
	k -= min(summ, 8)
	summ -= min(summ, 8)
	cnt += 1
	i += 1
if k > 0:
	print(-1)
else:
	print(cnt)


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
(s, x) = (0, 0)
for i in l:
	x += 1
	s += i
	if s <= 8:
		b -= s
		s = 0
	else:
		b -= 8
		s -= 8
	if b <= 0:
		break
if b > 0:
	print(-1)
else:
	print(x)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cc = 0
dc = 0
for t in a:
	dc += 1
	cc += t
	k -= min(8, cc)
	cc -= min(8, cc)
	if k <= 0:
		print(dc)
		break
else:
	print(-1)


n = input().split(' ')
k = int(n[1])
n = int(n[0])
days = 1
candies = input().split(' ')
for i in range(len(candies)):
	can = int(candies[i])
	if can > 8:
		k -= 8
		if i + 1 != len(candies):
			candies[i + 1] = int(candies[i + 1]) + can - 8
	else:
		k -= can
	if k < 1:
		print(days)
		break
	days += 1
if k > 0:
	print(-1)


import sys
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
r = 0
t = 0
for i in range(n):
	r += min(8, a[i] + t)
	t += a[i] - 8
	if t < 0:
		t = 0
	if r >= k:
		print(i + 1)
		sys.exit()
print(-1)


line1 = input().split()
day = int(line1[0])
k = int(line1[1])
a = []
for i in input().split():
	a.append(int(i))
remain = 0
ans = 0
for i in a:
	ans = ans + 1
	remain = remain + i
	if remain > 8:
		k = k - 8
		remain = remain - 8
		if k <= 0:
			break
	else:
		k = k - remain
		remain = 0
		if k <= 0:
			break
if k > 0:
	print(-1)
else:
	print(ans)


from sys import stdin
(n, k) = map(int, stdin.readline().rstrip().split())
data = list(map(int, stdin.readline().rstrip().split()))
count = 0
dcount = 0
accu = 0
for N in data:
	accu += N
	given = min(accu, 8)
	count += given
	accu -= given
	dcount += 1
	if count >= k:
		break
print(dcount if count >= k else -1)


(n, k) = (int(x) for x in input().strip().split())
a = list(map(int, input().split()))
i = 0
sum = 0
day = 0
flag = 0
rest = 0
while i < n:
	if a[i] > 8:
		rest += a[i] - 8
		a[i] = 8
	elif a[i] < 8 and rest > 0:
		a[i] += rest
		if a[i] > 8:
			rest = a[i] - 8
			a[i] = 8
		else:
			rest = 0
	sum += a[i]
	day += 1
	i += 1
	if sum >= k:
		flag = 1
		break
if flag == 1:
	print(day)
else:
	print(-1)


X = list(map(int, input().split()))
Candies = list(map(int, input().split()))
Count = 0
BranCandy = 0
SUM = 0
for i in range(len(Candies)):
	Count += 1
	SUM += Candies[i]
	if SUM >= 8:
		BranCandy += 8
		SUM -= 8
	else:
		BranCandy += SUM
		SUM = 0
	if BranCandy >= X[1]:
		print(Count)
		exit()
print(-1)


def main():
	inp1 = input().split(' ')
	(_, sweets) = map(int, inp1)
	inp2 = input().split(' ')
	sweets_counts = list(map(int, inp2))
	print(gift(sweets, sweets_counts))

def gift(sweets, sweets_counts):
	bran_total = 0
	aria_reserve = 0
	for i in range(len(sweets_counts)):
		current_day_sweets = aria_reserve + sweets_counts[i]
		to_bran = min(current_day_sweets, 8)
		bran_total += to_bran
		aria_reserve = current_day_sweets - to_bran
		if bran_total >= sweets:
			return i + 1
	return -1
main()


import math
(n, k) = input().split()
a = input().split()
n = int(n)
k = int(k)
sw_count = 0
day = 0
for i in range(n):
	if k <= 0:
		break
	sw_count += int(a[i])
	if sw_count // 8 > 0:
		sw_count -= 8
		k -= 8
	else:
		k -= sw_count
		sw_count = 0
	day += 1
if k > 0:
	day = -1
print(day)


def main():
	total = 0
	(n, k) = liee()
	a = array()
	cnt = 0
	for i in range(n):
		total += a[i]
		temp = min(8, total)
		cnt += temp
		total -= temp
		if cnt >= k:
			print(i + 1)
			exit()
	print(-1)
from sys import *
import inspect
import re
from math import *
import threading
from collections import *
from pprint import pprint as pp
mod = 998244353
MAX = 10 ** 5

def lie():
	return int(input())

def liee():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def deb(p):
	for line in inspect.getframeinfo(inspect.currentframe().f_back)[3]:
		m = re.search('\\bdeb\\s*\\(\\s*([A-Za-z_][A-Za-z0-9_]*)\\s*\\)', line)
		print('%s %s' % (m.group(1), str(p)))

def vec(size, val=0):
	vec = [val for i in range(size)]
	return vec

def mat(rowNum, colNum, val=0):
	mat = []
	for i in range(rowNum):
		collumn = [val for j in range(colNum)]
		mat.append(collumn)
	return mat

def dmain():
	setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
dmain()


import math
from sys import stdin, stdout
import bisect
m = 10 ** 9 + 7

def inp():
	return int(stdin.readline())

def inpstr():
	return list(stdin.readline().strip())

def inpli():
	return list(map(int, input().split()))

def inpmap():
	return map(int, input().split())

def opt(n):
	stdout.write(str(n) + '\n')

def bexp(n, p):
	r = 1
	while p > 0:
		if p % 2:
			r = r * n
			p = p - 1
		else:
			n = n ** 2
			p = p // 2
	return r

def gcd(a, b):
	while b:
		a = a % b
		(b, a) = (a, b)
	return a

def sieve(limit):
	l = [1] * (limit + 1)
	l[0] = 0
	l[1] = 0
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segs(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def code():
	s = 0
	c = 0
	(n, p) = inpmap()
	l = inpli()
	for i in l:
		s = s + i
		g = min(s, 8)
		p = p - g
		s = s - g
		c = c + 1
		if p <= 0:
			break
	if p > 0:
		print(-1)
	else:
		print(c)
	return
code()


(n, k) = map(int, input('').split())
a = list(map(int, input('').split()))
count = 0
ans = 0
for i in a:
	ans += i
	rem = min(8, ans)
	ans -= rem
	k -= rem
	count += 1
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(count)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
for i in range(len(a)):
	if k > 0:
		sum += 1
		if a[i] > 8:
			try:
				a[i + 1] += a[i] - 8
			except IndexError as e:
				pass
			k -= 8
		else:
			k -= a[i]
	else:
		break
if k <= 0:
	print(sum)
else:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
re = 0
for i in range(n):
	m = min(a[i] + re, 8)
	k -= m
	re += a[i] - m
	if k <= 0:
		exit(print(i + 1))
print(-1)


(n, k) = map(int, input().split())
l = map(int, input().split())
l = list(l)
if sum(l) < k or 8 * n < k:
	print(-1)
else:
	s = 0
	t = True
	i = 0
	d = 0
	while s < k:
		try:
			if l[i] >= 8:
				s += 8
				d += l[i] - 8
			else:
				s += l[i] + min(d, 8 - l[i])
				d -= min(d, 8 - l[i])
			i += 1
		except IndexError:
			t = False
			print(-1)
			break
	if t:
		print(i)


(n, k) = map(int, input().split())
a = list(map(int, input().strip().split()))
j = 0
now = 0
while k > 0 and j < n:
	j = j + 1
	now = now + a[j - 1]
	if now >= 8:
		k = k - 8
		now = now - 8
	else:
		k = k - now
		now = 0
if j == n and k > 0:
	print(-1)
else:
	print(j)


(n, k) = [int(i) for i in input().split()]
li = [int(x) for x in input().split()]
kek = 0
candies = 0
result = 0
yes = False
for i in range(n):
	kek += li[i]
	if li[i] >= 8:
		kek -= 8
		candies += 8
		result += 1
	elif kek <= 8:
		candies += kek
		kek = 0
		result += 1
	else:
		kek -= 8
		candies += 8
		result += 1
	if candies >= k:
		yes = True
		break
if yes:
	print(result)
else:
	print('-1')


firstrow = list(map(int, input().split()))
days = firstrow[0]
needtofeed = firstrow[1]
limitinday = 8
totalcandy = 0
candyperday = list(map(int, input().split()))
needdays = 0
for i in range(days):
	if needtofeed > 0:
		needdays += 1
	mn = min(candyperday[i], limitinday)
	needtofeed -= mn
	totalcandy += candyperday[i] - mn
	if i != days - 1:
		candyperday[i + 1] += candyperday[i] - mn
if needtofeed > 0:
	print(-1)
else:
	print(needdays)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(cnt, prv) = (0, 0)
for x in a:
	cnt += 1
	x += prv
	prv = 0
	if x > 8:
		k -= 8
		prv = x - 8
	else:
		k -= x
	if k <= 0:
		break
if k > 0:
	print(-1)
else:
	print(cnt)


from sys import stdin
i = [[int(y) for y in x.rstrip().split()] for x in stdin.readlines()]
k = i[0][1]
days = i[1]
remaining = 0
for (i, x) in enumerate(days):
	k -= min(8, x + remaining)
	remaining = x + remaining - min(8, x + remaining)
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
mn = list(map(int, input().split()))
(sm, mines, ans) = (0, 0, 0)
for i in range(n):
	sm += mn[i]
	mines = min(sm, 8)
	k -= mines
	ans += 1
	sm -= mines
	if k <= 0:
		print(ans)
		break
else:
	print(-1)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if 8 * n < k or sum(a) < k:
	print(-1)
else:
	cur = 0
	for i in range(n):
		cur += a[i]
		reduced_by = min(8, cur)
		k -= reduced_by
		cur -= reduced_by
		if k <= 0:
			print(i + 1)
			break
	else:
		print(-1)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
su = 0
t = 0
f = False
for i in s:
	k -= min(8, i + su)
	su += max(-su, i - 8)
	t += 1
	if k <= 0:
		f = True
		print(t)
		break
if not f:
	print(-1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
day = 0
num = 0
i = 0
while True:
	if a[i] > 8:
		a[i] -= 8
		num += 8
		if i + 1 <= n - 1:
			a[i + 1] += a[i]
	else:
		num += a[i]
		a[i] = 0
		if i + 1 <= n - 1:
			a[i + 1] += a[i]
	i += 1
	day += 1
	if num >= k or day == n:
		break
print(day if day > 0 and k <= num else -1)


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
p = 0
for i in range(n):
	if a[i] > 8:
		k -= 8
		p += a[i] - 8
	else:
		k -= a[i]
		if p != 0:
			k -= min(p, 8 - a[i])
			p -= min(p, 8 - a[i])
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


[n, k] = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
p = 0
while k > 0 and len(a) > 0:
	p += a.pop(0)
	k -= min(p, 8)
	p -= min(8, p)
print(-1 if k > 0 else n - len(a))


inp1 = input().split()
inp2 = input().split()
n = int(inp1[0])
k = int(inp1[1])
arya = 0
bran = 0
for i in range(1, n + 1):
	arya = arya + int(inp2[i - 1])
	if arya < 8:
		bran = bran + arya
		arya = 0
	else:
		bran = bran + 8
		arya = arya - 8
	if bran >= k:
		print(i)
		break
if bran < k:
	print(-1)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
cur = 0
for i in range(n):
	cur += l[i]
	k -= min(cur, 8)
	cur -= min(cur, 8)
	if k <= 0:
		print(i + 1)
		break
else:
	print(-1)


(n, k) = map(int, input().split())
(a, res, day) = (0, -1, 1)
for i in input().split():
	a += int(i)
	if a >= 8:
		k -= 8
		a -= 8
	else:
		k -= a
		a = 0
	if k <= 0:
		res = day
		break
	day += 1
print(res)