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 ai 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.

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10000). The second line contains n integers a1, a2, a3, ..., an (1 ≤ ai ≤ 100).

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.

NoteIn 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.

#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
	int n,k,max=0,sum=0,out=-1;
	bool flag = true;
	cin >> n >> k;
	for(int i = 0; i<n; i++)
	{
		int temp;
		cin >> temp;
		sum += temp;
		if(sum>=8){
		max +=8;
		sum -=8;
		}
		else{
		max +=sum;
		sum = 0;
		}

		if(max>=k&&flag){
		out = i+1;
		flag = false;
		}
	}
	cout << out;
}

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int n, k, a, i, s, d, l;
	cin >> n >> k;
	i = 1; s = 0; d = 0; l = 0;
	while ((n >= 1 && n <= 100) && (k >= 1 && k <= 10000) && (i <= n))
	{
		cin >> a;
		if (a >= 8) s = s + 8;
		else if ((a + l) >= 8)
			s = s + 8;
		else if ((a + l) < 8 && l >= 0)
			s = s + a + l;
		else s = s + a;
		if (s >= k && d == 0)
			d = i;
		l = l + a - 8;
		i++;
	}
	if (s >= k)
		cout << d << endl;
	else if (s < k)
		cout << "-1" << endl;
	return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
  int sum = 0, count = 0, a, days = 0;
  bool t = false;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (sum < k) {
      if (a >= 8) {
        sum += 8;
      }
      else {
        sum += a;
        sum += min(8 - a, count);
        if (count > 8 - a) {
          count -= 8 - a;
        }
        else {
          count = 0;
        }
      }
      days++;
    }
    count += max(a - 8, 0);
  }
  if (sum >= k) {
    cout << days;
  }
  else {
    cout << -1;
  }
}

#include <iostream>

using namespace std;

int main(){
    int days;
    int candles;

    cin >> days;
    cin >> candles;
    int counter = -1;
    int temp;
    int r = 0;
    int total = 0;
    for(int i=0; i<days; i++){
        cin >> temp;
        if(temp > 8){
            r += temp - 8;
            temp = 8;
        }
        if(counter < 0){
            counter = 1;
        }
        else{
            if(total < candles) counter++;
        }
        if(temp<8){
            if(8-temp <=r){
                r-=(8-temp);
                temp = 8;
            }
            if(r+temp <=8){
                temp+=r;
                r=0;
            }
        }
        if((total+=temp) > candles){
            break;
        }
    }

    if(total < candles){
        cout << -1;
    }
    else{
        cout << counter;
    }

    return 0;
}

#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<vector>
#define mod 1000000007
#define mm(i,n) for(int i=0;i<n;i++)
const double pi = 3.1415926;
using namespace std;

long long fact(long long n)
{
	long long f = 1;
	for (long long i = n; i >= 1; i--)
		f *= i;
	return f;
}

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a%b);
}

int divisor(int n)
{
	int sum = 0;
	if (n / sqrt(n) == sqrt(n))
		sum++;
	for (int i = 1; i < sqrt(n); i++)
		if (n%i == 0)
			sum += 2;
	return sum;
}

bool prime(long long n)
{
	for (long long i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
	return true;
}

bool palindrome_str(string n)
{
	int x = 0;
	int m = n.size() / 2 - 1;
	int r = n.size();
	for (int i = 0; i < m; i++)
		if (n[i] == n[r - i - 1])
			x++;
	if (x == m)
		return true;
	return false;
}

bool palindrome_num(int n)
{
	int x = 0, a[10000], r = 0;
	while (n)
	{
		a[r++] = n % 10;
		n /= 10;
	}
	for (int i = 0; i < r / 2; i++)
		if (a[i] == a[r - i - 1])
			x++;
	if (x == r / 2)
		return true;
	return false;
}

void small(string &n)
{
	for (int i = 0; i < n.size(); i++)
		if (n[i] >= 'A'&&n[i] <= 'Z')
			n[i] += 32;
}

void capital(string &n)
{
	for (int i = 0; i < n.size(); i++)
		if (n[i] >= 'a'&&n[i] <= 'z')
			n[i] -= 32;
}

long long fast_power(long long n, long long m)
{
	if (m == 0)
		return 0;
	if (m == 1)
		return n;
	long long x = fast_power(n, m / 2) % mod;
	x = (x*x) % mod;
	if (m % 2 != 0)
		x *= n;
	x %= mod;
	return x;
}

void fast()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

vector<int> vec;

int main()
{
	//freopen("gift.in", "r", stdin);
	//freopen("gift.out", "w", stdout);
	fast();
	int n, k,x[102];
	cin >> n >> k;
	mm(i, n)
		cin >> x[i];
	mm(i, n)
	{
		if (x[i] > 8)
		{
			k -= 8;
			if (i != n - 1)
				x[i + 1] += x[i] - 8;
		}
		else
			k -= x[i];
		if (k <= 0)
		{
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	//system("pause");
}

#include <iostream>

using namespace std;

int main() {

  int n, k;

  cin >> n >> k;

  int arya = 0, bran = 0;

  int mnd = 0;

  for (int i = 0; i < n; ++i) {

    int today;

    cin >> today;

    if (today + arya >= 8) {

      bran += 8;

      arya += today - 8;

      ++mnd;

    } else {

      bran += today + arya;

      arya = 0;

      ++mnd;

    }

    if (bran >= k) {

      cout << mnd << "\n";

      return 0;

    }

  }

  if (bran < k) {

    cout << -1 << "\n";

  }

  return 0;

}

#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n, k, sum(0), idk;
  cin >> n >> k;
  int arr[n+1];

  for (int i=1; i<=n; i++)
  {
    cin >> arr[i];
  }

  for (int i=1; i<=n; i++)
  {
    sum += arr[i];
    if (sum > 8) {sum -= 8; k -= 8;}
    else {k -= sum; sum = 0;}
    if (k<=0) {idk=i; break;}
  }
  if (k>0)
      cout << -1 << endl;
  else
      cout << idk << endl;

  return 0;
}

//ID: 18127217
//Name: TRINH MINH THANH
//Ex07: 839A

#include <iostream>

using namespace std;

int main()
{
	int m, n, k, j;
	int count = 0;
	cin >> n;
	cin >> k;
	m = 0;
	j = 0;
	int S = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		if (m + j >= 8)
		{
			S = S + 8;
			j = j + m - 8;
			++count;
		}
		else if (m + j < 8)
		{
			S = S + m + j;
			j = 0;
			++count;
		}

		if (S >= k)
		{
			cout << count;
			return 0;
		}
	}
	if (S < k)
		cout << "-1";
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
	int n, k, a[110];
	cin >> n >> k;
	for(int i =0; i < n; i ++)
	{
		cin >> a[i];
	}

	int cnt = 0;
	for(int i =0; i < n; i++)
	{
		cnt += a[i];
		if(8 < cnt)
		{
			k-= 8;
			cnt -=8;
		}

		else
		{
			k -= cnt;
			cnt =0;
		}

		if(k <= 0)
		{
			cout << i + 1 << endl;
			return 0;
		}
	}

	cout << -1<< endl;
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <iterator>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	int* mas1 = new int[n];
	memset(mas1, 0, 4 * n);
	for (int i = 0; i < n; i++){
		cin >> mas1[i];
	}
	int count_day = 0;
	int sum = 0;
	for (int i = 0; i < n-1; i++){
		if (mas1[i]>8){
			sum += 8;
			mas1[i + 1] += (mas1[i] - 8);
			count_day++;
		}
		else {
			sum += mas1[i];
			count_day++;
		}
		if (sum >= k){
			count_day--;
			break;
		}
	}
	mas1[n - 1] > 8 ? sum += 8 : sum += mas1[n - 1];
	count_day++;
	if (sum < k || n * 8 < k){
		cout << "-1";
	}
	else {
		cout << count_day;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int n,a,k,t,f;
int main()
{cin>>n>>k;
 for(int i=1;i<=n;i++)
   {cin>>a;
    t+=min(a+f,8);
    f=max(a+f-8,0);
    if(t>=k) {cout<<i;
              return 0;}
   }
 cout<<-1;
 return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"

using namespace std;

int inf = std::numeric_limits<int>().max();
int inf_l = std::numeric_limits<long long>().max();

#define BUFF ios::sync_with_stdio(false)

#define vb vector<bool>
#define vvb vector<vb>
#define vi vector<int>
#define vvi vector<vi>
#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define all(c) (c).begin(), (c).end()
#define trv(v, i) for (int i=0; i<v.size(); i++)
#define sc(x) scanf("%d", &x)
#define sc2(x, y) scanf("%d %d", &x, &y)
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z)
#define scs(s) scanf("%s", s)
#define scs2(s1, s2) scanf("%s %s", s1, s2)
#define pri(x) printf("%d\n", x)
#define prie(x) printf("%d ", x)
#define pb push_back
#define nl printf("\n");

#define mod 1000000007   // 1e9+7
inline ll soma(ll x, ll y) {
   return (x % mod + y % mod) % mod;
}
inline ll subtrai(ll x, ll y) {
   return ((x % mod - y % mod) + mod) % mod;
}
inline ll multiplica(ll x, ll y) {
   return (x % mod * y % mod) % mod;
}

struct S {
   int l, r;
   int cost;
   bool operator() (S i, S j) { return (i.r - i.l < j.r - j.l);}
} reg;
// sort(vs.begin(), vs.end(), reg);

ll teto(ll a, ll b) {
   return a/b + (a % b != 0);
}

int gcd(int a, int b) {
   if (a % b == 0) {
      return b;
   } else return gcd(b, a-b);
}

int binary(int e, vll & v) { // a=1 b=n is OK!
   int a=0;
   int b=v.size()-1;
   while (a<=b) {
      int k = (a+b)/2;
      if (v[k] == e) return k;
      if (v[k] > e) b = k-1;
      if (v[k] < e) a = k+1;
   }
   return -1;
}

// Strings:

// str[i] += 'A' + 32; // 'a'
// str[i] += '+';
// str[i] += '2';    // str = "A+2"
// a[i] - 0 < 97    // maiuscula.   'a' == 97
// sort(all(a));
int char_to_int(string s, int i) {
   int d = s[i] - '0';
   return d;
}

bool double_is_int(double alpha) {
   return abs(alpha - floor(alpha)) <= 10e-7;
}

int minimo(int x, int y) {
   if (x<y)
      return x;
   else return y;
}

int main() {
   BUFF;

   long n, k;
   cin >> n >> k;
   vll a(n+1, 0);
   for (int i=1; i<=n; i++) {
      cin >> a[i];
   }

   int is=-1;
   long long total = 0;
   bool vf = 0;
   int i=1;
   while (!vf and i<=n) {
      if (minimo(a[i],8) + total >= k) {
         vf = 1;
         is = i;
      } else if (i < n) {
         total += minimo(a[i], 8);
         if (a[i] > 8) {
            a[i+1] += a[i] - 8;
         }
      }
      i++;
   }

   cout << is << endl;

   return 0;
}

// ID: 19125089
// NAME: PHAM THI NGOC HA
// CLASS: 19CTT1

// Testcase 1:
// Input:  2 3
//         1 2
// Output: 2

// Testcase 2:
// Input:  3 17
//         10 10 10
// Output: 3

// Testcase 3:
// Input:  1 9
//         10
// Output: -14

#include <iostream>

int main() {
    int n;
    int k;
    int a = 0;
    int b = 0; // candy left from the day before

    std::cin >> n >> k;

    for (int i = 0; i < n; i++) {
        std::cin >> a;
        a += b;
        if (a > 8) {
            k -= 8;
            b = a - 8;
        }
        else {
            k -= a;
            b = 0;
        }
        if (k <= 0) {
            std::cout << i + 1;
            return 0;
        }
    }
    std::cout << "-1";
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>

using namespace std;

int a[100000];
int main()
{
	int n, m;
	cin >> n >> m;
	a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int temp = 0;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += min(8, temp + a[i]);
		if (temp + a[i] <= 8){
			temp = 0;
		}
		else {
			temp = (temp + a[i]) - 8;
		}
		if (ans >= m){
			cout << i + 1;
			return 0;
		}
	}
	cout << -1;
	return 0;

}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N, K; cin >> N >> K;
  vector<int> a(N+1);
  for(int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int sum = 0;
  for(int i = 0; i < N; i++) {
    if(a[i] > 8) {
      sum += 8;
      a[i+1] += a[i] - 8;
    } else {
      sum += a[i];
    }
    if(sum >= K) {
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

#include "iostream"
#include "math.h"

using namespace std;
int main()
{
	int n, k;
	cin >> n;
	cin >> k;
	int x=0,temp;
	int dem = 0;
	for (int i = 1;i <= n;i++)
	{
		cin >> temp;
		x = x + temp;
		if (k <= 0) break;
		dem++;
		if (x > 8)
		{
			k = k - 8;
			x=x - 8;
		}
		else
		{
			if (k <= x)
			{
				k = 0;
				x = x - k;
			}
			else
			{
				k = k - x;
				x = 0;
			}
		}
	}
	if (k > 0 || dem > n)
		cout << "-1";
	else
		cout << dem;
	return 0;
 }

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here

	int n,k,i,count=0;
	int arr[104];
	bool set=false;

	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=1;i<=n;i++)
	{

		if(arr[i]<=8)
		{
			k=k-arr[i];
		}
		else
		{
			k=k-8;
			arr[i+1]=arr[i+1]+arr[i]-8;
		}
		count++;
		if(k<=0)
		{
			set=true;
			printf("%d\n",i);
			break;
		}
	}

	if(i>n && set==false)
	printf("-1\n");
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int a,b,i,c=0;
  cin>>a>>b;

  int A[a];
  for(i=0;i<a;i++){
      cin>>A[i];

  }
  for(i=0;i<a;i++){

      if(b>0){
         if(A[i]>8){
          b=b-8;
          A[i+1]=A[i+1]+(A[i]-8);
        }
        else{
          b=b-A[i];
         }
         c++;
      }

  }
  if(b<=0)
    cout<<c<<endl;

    else{
        cout<<-1;
    }
}

//Date:2017/8/16
//OJ:codeforces
//Problem:839-A
//Solution:Simulation
//By:xushengyuan
#include <bits/stdc++.h>
using namespace std;
int n,k,sum=0;
int main()
{
    #ifdef _DEBUG
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    cin >>n>>k;
    int t,result=0;
    if(8*n<k)
    {
        cout <<-1;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        cin >>t;
        sum+=t;
        int f=min(8,min(k,sum));
        k-=f;
        sum-=f;
        result++;
        if(k==0)
            break;
    }
    if(k==0)
        cout <<result;
    else
        cout <<-1;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int h=0;
long long g=0;
for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    g+=a;
    if(g>=8){
        h+=8;
        g-=8;
    }
    else{
        h+=g;
        g=0;
    }
    if(h>=k){
        cout<<i;
        return 0;
    }
}
cout<<-1;
}

#include <iostream>
using namespace std;

int main()
{
	setlocale(LC_ALL, "RUS");
	int n, k, a, j = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		a += j;
		j = 0;
		if (a <= 8)
			k -= a;
		else
		{
			k -= 8;
			j = a - 8;
		}
		if (k <= 0)
		{
			cout << i + 1;
			return 0;
		}
	}
	cout << "-1";
	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	int arya = 0, bran = 0, n, day = 0, k, a, i;
	cin >> n >> k;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a + arya > 8)
		{
			bran = bran + 8;
			arya = arya + a - 8;
			day++;
		}
		else
		{
			bran = bran + a + arya;
			arya = 0;
			day++;
		}
		if (bran >= k)
		{
			cout << day;
			break;
		}
	}
	if (bran < k) cout << -1;
	return 0;
}

// ID : 1751085
// Name : Nguyen Mac Bao Ngoc
// Ex07 : Candies

#include<iostream>
using namespace std;
int main()
{
	int n, a, k, s = 0, m = 0, d=0;
	cin >> n;
	cin >> k;
	while (d < n && s < k)
	{
		cin >> a;
		m = m + a;
		if (m < 8)
		{
			s = s + m;
			m = 0;
		}
		else
		{
			s = s + 8;
			m = m - 8;
		}
		++d;
	}
	if (s >= k)
		cout << d << endl;
	else
		cout << -1 << endl;
	return 0;
}

#include<iostream>
using namespace std;
#include<math.h>

void main()
{
	int n, k, i, j, du;
	cin >> n >> k;
	du = 0;
	i = 1;
	while (i <= n)
	{
		cin >> j;
		//cout << j<<"/";
		j += du;
		if (k >= j)
		{
			if (j <= 8)
			{
				k -= j;
				du = 0;
			}
			if (j > 8)
			{
					k -= 8;
					du = j - 8;
			}
		}

		else if (k < j)
		{
			if (k <= 8) k = 0;
			if (k > 8)
			{
				k -= 8;
				du = j - 8;
			}
		}
		//cout << i << "/" << k << "/" << du << "/" << j << endl;
		if (k == 0)  break;
		i++;
	}
	if (i <= n) cout << i; else cout << "-1";
	//system("pause");
}

#include<cstdio>
#include<iostream>
using namespace std;
int n,k,now,ans,i=1;
int main(void){
    scanf("%d%d",&n,&k);
    for(;i<=n;i++){
        int a;
        scanf("%d",&a);
        if(a>8){
			ans+=8;
			now+=a-8;
        }else if(a<=8&&!now){
			ans+=a;
        }else if(now+a<=8){
			ans+=now+a,now=0;
        }else{
			ans+=8,now-=8-a;
		}
        if(ans>=k){
			break;
		}
    }
    if(i>n&&ans<k){
		printf("-1");
    }else{
		printf("%d",i);
	}
	return 0;
}

#include<iostream>
using namespace std;
int a[105];
int main()
{
int n,k,i,c=0,l=0;
cin>>n>>k;
for(i=0;i<n;i++) cin>>a[i];
for(i=0;i<n;i++)
{
c++;
l=l+a[i];
if(l>8) {k=k-8; l=l-8; }
else { k=k-l; l=0;}
if(k<=0) break;}
if(i==n) c=-1;
cout<<c;}

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int  n,a,k,b,s=0,s1=0;
	cin>>n>>k;
	for (int i=1; i<=n;i++)
	{
		cin>>a;
		s1+=a;
		b=min(s1,8);
		s+=b;
		s1-=min(8,b);
		if (s>=k)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}

#include <iostream>

using namespace std;

int main() {

  int n, k;

  cin >> n >> k;

  int arya = 0, bran = 0;

  int mnd = 0;

  for (int i = 0; i < n; ++i) {

    int today;

    cin >> today;

    if (today + arya >= 8) {

      bran += 8;

      arya += today - 8;

      ++mnd;

    } else {

      bran += today + arya;

      arya = 0;

      ++mnd;

    }

    if (bran >= k) {

      cout << mnd << "\n";

      return 0;

    }

  }

  if (bran < k) {

    cout << -1 << "\n";

  }

  return 0;

}

//solution of the problem based on the code posted by user kantuni on github.com
#include <iostream>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    int a,b,mnd,candie;
    a = b = mnd = 0;
    for(int i = 0; i < n; i++){
        cin >> candie;
        if(candie+a >= 8){
            b+=8;
            a+=candie-8;
            mnd++;
        }
        else{
            b+=candie+a;
            a = 0;
            mnd++;
        }
        if(b >= k){
            cout << mnd << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

//ID: 18127217
//Name: TRINH MINH THANH
//Ex07: 839A

#include <iostream>

using namespace std;

int main()
{
	int n, k, m, j;
	int count = 0;
	cin >> n;
	cin >> k;
	m = 0;
	j = 0;
	int S = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		if (m + j >= 8)
		{
			S = S + 8;
			j = j + m - 8;
			++count;
		}
		else if (m + j < 8)
		{
			S = S + m + j;
			j = 0;
			++count;
		}

		if (S >= k)
		{
			cout << count;
			return 0;
		}
	}
	if (S < k)
		cout << -1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i;
	cin>>n>>k;
	long long int a[n],ans=0,p=0;
	for(i=0;i<n;i++)
	cin>>a[i];

	for(i=0;i<n;i++)
	{
		/*if(ans>=k)
		{cout<<i;return 0;
		}*/
		a[i]+=p;
		if(a[i]>8)
		{
			ans+=8;p=a[i]-8;
		}
		else
		{
			ans+=a[i];p=0;
		}
		if(ans>=k)
		{cout<<i+1;return 0;
		}
	}
	cout<<"-1";
	return 0;
}

#include <string>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main () {
	int n ,k;
	cin>>n>>k;
	int day = 0;
	int summa =0 ;
	int summa1=0;
	int arr[n];
	int s;
	for (int i =0 ; i<n;i++) {
		cin>>s;
		arr[i]=s;
	}
	for (int i = 0; i<n;i++) {
		if (arr[i]>8) {
		   arr[i+1]+=arr[i]-8;
		}
	}

	for (int i =0 ; i<n;i++) {
		if (arr[i]>8) {
		   summa+=8;
		}
		else {
			 summa+=arr[i];
		}
		if (summa>=k) {
		   cout<<i+1;
		   return 0;
		}
	}
	cout<<-1;
	return 0;
}

#include <stdio.h>
void main()
{
	long int n, k, a, a1=0, cnt=0, d=0, i;
	scanf("%ld%ld", &n, &k);
	for(i=0; i<n; i++)
	{
		scanf("%ld", &a);
		a=a+a1;
		if(a>8)
		{
			d=d+8;
			a1=a-8;
		}
		else
		{
			d=d+a;
			a1=0;
		}
		cnt++;
		if(d>=k)
		{
			printf("%ld", cnt);
			return;
		}
	}
	printf("-1");
}

#include <bits/stdc++.h>
using namespace std;

int n, k, r, x, q;

void pause() {
    while (1);
}

int main() {
    #ifndef ONLINE_JUDGE
    atexit(pause);
    #endif
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> r;
        x += r;
        q += min(x, 8);
        x -= min(x, 8);
        if (q >= k) {
            cout << i;
            return 0;
        }
    }
    cout << -1;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    while(1)
    {
        int n,m;
        cin>>n>>m;
        int a[n];
        int sum = 0;
        int sum1= 0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
        for(int i=0;i<n-1;i++)
        {
            if(a[i]>8)
            {
                a[i+1]+=a[i]-8;
                a[i]=8;
            }
        }
        int count  = 0;
        for(int i=0;i<n;i++)
        {
            if(m<=0)
                break;
         if(i==n-1 && m>8)
            {
                cout<<"-1\n";
                return 0;
            }
            if(m!=0)
            {
                m-=a[i];
                count++;
            }

        };
        if(m>0)
        {
            cout<<"-1\n";
            return 0;
        }
        cout<< count << endl;
        return 0;
    }
}

#include <iostream>
using namespace std;
int main()
{
	int n, k, i, a;
	cin >> n >> k;
	i = 1;
	int sum = 0;
	int count = 0;
	int du = 0;

	while (i <= n)
	{
		cin >> a;

		if (sum ==k){
		    break;
		}else{
		    if (a + du > 8){
		        if (sum + 8 <=k){
		            sum = sum + 8;
		            count = count + 1;
		            du = a + du - 8;
		        }else{
		            sum = k;
		            count = count + 1;
		            break;
		        }
		    }else{
		       if (sum + a + du <=k){
		           sum = sum + a + du;
		           du = 0;
		           count = count + 1;
		       }else{
		           sum = k;
		           count = count + 1;
		           break;
		       }
		    }
		}

		i = i + 1;
	}

	if (sum!=k) cout << "-1" << endl;
	else cout << count << endl;

}

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k;
	cin>>n>>k;
	int array[n+1];
	int cnt=0;
	int sum=0;
	array[0]=0;
	for(int i =1;i<=n;i++)
	{
		cin>>array[i];
		sum+=array[i];
		if(array[i-1]>8)
			array[i]+=array[i-1]-8;

	}
	//cout<<sum<<endl;
	int given=0;
	int res=0;
	int ans=0;
	bool flag=true;
	for(int i =1;i<=n;i++)
	{

		if(array[i]<=8)
		{
			cnt++;

			given+=array[i];
		}
		else
		{
			given+=8;
			res+=array[i]-8;
			cnt++;
		}
		if(given>=k)
		{
			 ans=i;
			 flag=false;
			break;

		}

	}
	 if(given>=k&&flag==false)
		cout<<ans<<endl;
	else cout<<"-1"<<endl;

}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <sstream>

using namespace std;
map<int, int> m;

bool simple(long long n)
{
	if (m[n])
		return true;
	for (int i = 2; i* i <= n; ++i)
	{
		if (n % i == 0)
			return false;
	}
	m[n] = 1;
	return true;
}

bool t_simple(long long n)
{
	long long s = int(sqrt(n));
	if (int(s*s == n))
	{
		if (simple(s))
		{
			return true;
		}
	}
	return false;
}

int diff(int n1, int n2)
{
	int a = n1 ^ n2;
	int count = 0;
	for (; a != 0; ++count)
	{
		a &= a - 1;
	}
	return count;
}

int main()
{
	ios_base::sync_with_stdio(0);

	int n, k;
	cin >> n >>  k;
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	int sum = 0;
	int  count = 0;
	for (int i = 0; i < n; ++i)
	{
		sum += v[i];
		if (k >= 8)
		{
			if (sum >= 8)
			{
				k -= 8;
				sum -= 8;
			}
			else
			{
				k -= sum;
				sum = 0;

			}
			++count;
		}
		else
		{
			if (sum >= 8)
			{
				if (k == 0)
					break;
				k = 0;
				++count;
				break;
			}
			else
			{
				if (sum < k)
				{
					++count;
					k -= sum;
					sum = 0;
				}
				else
				{
					if (k == 0)
						break;
					k = 0;
					++count;
					break;
				}
			}
		}
	}
	if (k != 0)
	{
		cout << -1 << endl;
		return 0;
	}
	cout << count << endl;
}

#include <iostream>

using namespace std;

int main()
{
    int n,k,sum=0;
    cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++)
        cin>>A[i];
    if(k>8*n)
    {cout<<-1; return 0;}
    for(int i=0;i<n-1;i++)
    {
        sum+=((A[i]<8)?A[i]:8);
        A[i+1]+=(A[i]-8)*(A[i]>8);
        A[i]=0;
        if(sum>=k)
        {
            cout<<i+1; return 0;
        }
    }
    sum+=((A[n-1]<8)?A[n-1]:8);
    if(sum>=k)
        cout<<n;
    else
        cout<<-1;
    return 0;
}

#include <vector>
#include <iostream>
#include <string>
#include <vector>

using std::vector;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int n, k;
	std::cin >> n >> k;

	vector<int> data(n);
	for (auto& elem : data) {
		std::cin >> elem;
	}

  int cur = 0, ans = 0;
  while (ans < n) {
  	cur += data[ans];
  	int r = std::min(8, cur);
  	cur -= r;
  	k -= r;
  	++ans;
  	if (k <= 0) {
  		break;
  	}
  }

  if (k > 0) {
  	std::cout << -1;
  	return 0;
  }

  std::cout << ans;

	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
const ll MOD = 1e9 + 7;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
using namespace std;

void vok()
{
    FAST
    FO
    FI
 }
ll gcd(ll a,ll b)
 {
     if(b==0)
       return a;
     return gcd(b,a%b);
 }
ll lcm(ll a,ll b)
 {
     return ((a*b)/gcd(a,b));
    }

 vector<ll>pp;
void gen()
 {
    vector<bool>prime(33000,true);
    prime[0]=prime[1]=false;
    for(int p=0;p*p<=33000;p++)
     {
         if(prime[p]){
         for(int i=p*p;i<=33000;i+=p)
            prime[i]=false;
         }
     }
    for(int i=0;i<33000;i++)
      if(prime[i])
         pp.push_back(i);
      //  cout<<i<<" ";

 }
ll find(vector<int>&A,int n)
{

}
void solve()
 {
    ll n,m,x,y,a,b,c,d,k;
    ll mx=-1;
    ll mi;

    a=b=x=y=k=c=0;
    ll ans=0,res=0;
    cin>>n>>k;
    string str;

    vector<int>A;
    for(int i=0;i<n;i++)
     {
         cin>>a;
         //cout<<" x "<<x<<endl;
         a+=y;
         y=0;
         if(a>8){
           x+=8;
           y=a-8;
         }
         else
           x+=a;

         if(x>=k)
           {
            cout<<i+1<<endl;
            return ;
           }
        // A.push_back(a);
     }

      cout<<"-1"<<endl;
     //cout<<find(A,n)<<endl;

}
int main()
{
  vok();

   int t = 1; //cin >> t;
    while(t--)
  {
      solve();

  }

   return 0;
}

#include <iostream>
using namespace std;
int main(){
	int n,k,a=0,x;
	cin>>n>>k;
	for(int i=1; i<=n; i++){
		cin>>x;
		a+=x;
		if(a>8){
			k-=8;
			a-=8;
		}
		else{
			k-=a;
			a=0;
		}
		if(k<=0){
			cout<<i;
			return 0;
		}
	}
	cout<<-1;
}

#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define fi first
#define se second

// code //
int mxN = 1e2 + 5;
int n, k;
vector<int> day(mxN);

void solve() {
	int ind = -1, pref = 0;

	for(int i = 0; i< n; ++i) {
		if(day[i] > 8) {
			k -= 8;
		} else {
			if(pref >= 8 - day[i]) {
				pref -= 8 - day[i];
				k -= 8;
			} else {
				k -= day[i] + pref;
				pref = 0;
			}
		}

		pref += day[i] > 8 ? day[i] - 8 : 0;

		//cout << "k : " << k << "  pref : " << pref << endl;

		if(0 >= k) {
			ind = i + 1;
			break;
		}
	}

	cout << ind;
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &day[i]);
	}

	solve();
}

#include <iostream>
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

const ll INF = 1e18 + 1;
const ll N = 1e5;
const ll MOD = 1e18 + 1;

using namespace std;

vector<ll> b;
vector< vector<ll> > g(N + 5);
ll n, m, k, r, x, y, l, c, t, cur, ans, mn(INF), mx(-INF), a[N + 5];
char c1, c2;
string s;
bool f, fl, used[N + 5];

void read(ll &in)
{
    scanf("%I64d", &in);
}

void read(ll &in1, ll &in2)
{
    scanf("%I64d%I64d", &in1, &in2);
}
void read(ll &in1, ll &in2, ll &in3)
{
    scanf("%I64d%I64d%I64d", &in1, &in2, &in3);
}

ll gcd (ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

void dfs(ll x)
{
    used[x] = true;
    for(int i = 0; i < g[x].size(); i++)
    {
        if(!used[g[x][i]])
        {
            dfs(g[x][i]);
        }
    }
}

ll bpow(ll x, ll p)
{
    ll res;
    if(p == 0)
    {
        return 1;
    }
    else
    {
        res = bpow(x, p / 2);
        res = (res * res) % MOD;
        if(p % 2 == 1)
        {
            res = (res * x) % MOD;
        }
        return res;
    }
}
/* Simple binary search
l = 0;
r = smth.size() - 1;
while(l < r)
{
    m = (l + r) / 2;
    if(x <= smth[m])
    {
        r = m;
    }
    else
    {
        l = m + 1;
    }
}
*/
int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    read(n, k);
    for(int i = 0; i < n; i++)
    {
        read(c);
        cur += c;
        if(cur <= 8)
        {
            k -= cur;
            cur = 0;
        }
        else
        {
            k -= 8;
            cur -= 8;
        }
        if(k <= 0)
        {
            cout << i + 1;
            return 0;
        }
    }
    cout << -1;
    return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"

using namespace std;

int inf = std::numeric_limits<int>().max();
int inf_l = std::numeric_limits<long long>().max();

#define BUFF ios::sync_with_stdio(false)
#define PI 3.1415926535
#define epsilon 1e-07
#define mod 1000000007   // 1e9+7

inline long long soma(long long x, long long y) {
   return (x % mod + y % mod) % mod;
}
inline long long subtrai(long long x, long long y) {
   return ((x % mod - y % mod) + mod) % mod;
}
inline long long multiplica(long long x, long long y) {
   return (x % mod * y % mod) % mod;
}

int main() {
   BUFF;

   int n, k;
	cin >> n >> k;
	vector<int> v(n+1);
	for(int i=1; i<=n; i++) {
		cin >> v[i];
	}
	int ans = 0;
	int saldo = 0;
	int i = 1;
	while (saldo < k and i<=n) {
		if (v[i] > 8) {
			saldo += 8;
			if (i<n) {
				v[i+1] = v[i+1] + v[i]-8;
			}
		} else {
			saldo += v[i];
		}
		i++;
	}
	ans = i-1;
	if (saldo < k) {
		ans = -1;
	}
	cout << ans << endl;
   return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define fname "a"

typedef long long ll;

void freac() {
#ifndef ONLINE_JUDGE
    freopen(fname".in", "r", stdin);
    freopen(fname".out", "w", stdout);
#endif
}

const int DX[] = {+1, 0, -1, 0, +1, +1, -1, -1};
const int DY[] = {0, +1, 0, -1, +1, -1, +1, -1};

const int INF = (int) 1e9 + 123;
const ll INFL = (ll) 1e18 + 123;
const double EPS = 1e-9;

template<class T> bool uin(T &a, T b) {
	return a > b ? (a = b, true) : false;
}

template<class T> bool uax(T &a, T b) {
	return a < b ? (a = b, true) : false;
}

void lifestyle() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

int main() {
	lifestyle();
	freac();
	int n, k;
	cin >> n >> k;
	int x; int gather = 0;
	for (int i = 1; i <= n; i++) {
		cin >> x; gather += x;
		k -= min(8, gather);
		gather = max(gather - 8, 0);
		if (k <= 0) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return false;
}

#include<bits/stdc++.h>

using namespace std;

int main(){

        long long n,k;

        cin>>n>>k;

        int t,c=0,s=0;

        for(int i=1;i<=n;++i){
                cin>>t;

                s=s+t;

                int r=min(8,s);

                s=s-r;

                k=k-r;

                if(k<=0) {
                        cout<<i;
                        break;}
        }

        if(k>0) cout<<-1;

}

#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cctype>
#include <set>
#include <numeric>
#include <bitset>

using namespace std;

typedef unsigned int ui;
typedef long long int lli;
typedef long int li;
typedef long double ld;
typedef unsigned long long int ulli;

template<class TypeName>void print(TypeName value) {
	cout << value << " ";
}
template<class TypeName>void println(TypeName value) {
	cout << value << endl;
}

int arraySum(int arr[], int len) {
	int init_sum = 0;
	return accumulate(arr, arr + len, init_sum);
}

string& toUpper(string& value) {
	for (ui i = 0; i < value.length(); i++) {
		value[i] = toupper(value[i]);
	}
	return value;
}
string& toLower(string& value) {
	for (ui i = 0; i < value.length(); i++) {
		value[i] = tolower(value[i]);
	}
	return value;
}

ui strchr(string value, char find) {
	for (ui i = 0; i < value.length(); i++) {
		if (value[i] == find) return i;
	}
	return -1;
}

string strrev(string value) {
	string temp;
	for (auto i = value.rbegin(); i != value.rend(); i++) {
		temp.push_back(*i);
	}
	return temp;
}

template<class T> void swap(T& a, T& b) {
	T x = a;
	a = b;
	b = x;
}

bool is_even(lli value) {
	if (value % 2 == 0) {
		return true;
	}
	return false;
}

//const int arsize = 200000;
//
//int problems[arsize] = {};

int main() {
	//97 - 122
	//48 - 57
	//65 - 90
	cout << fixed;
	cout << setprecision(0);
	ios::sync_with_stdio(0);
	cin.tie(0);

	vector<int> vec;

	int n, k, d = 0;

	cin >> n >> k;

	for (ui i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		vec.push_back(temp);
	}

	for (ui i = 0; i < n; i++) {
		// max
		if (vec[i] > 8 && i!=n-1) {
			vec[i + 1] += vec[i] - 8;
		}
		if (vec[i] > 8) {
			vec[i] -= (vec[i]-8);
		}

		k = k - vec[i];

		if (k <= 0) {
			d = i + 1;
			break;
		}
	}

	if (!d) {
		println(-1);
	}
	else {
		println(d);
	}

}

#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
	long long n,k,num,sum=0,dem=-1,give=0;
	//freopen("list.txt","r",stdin);
	cin>>n>>k;
	for (long long i=1;i<=n;i++)
	{
		cin>>num;
		sum=sum+num;
		if (give<k)
		{
			if (sum>=8)
			{
				give=give+8;
				sum=sum-8;
			}
			else
			{
				give=give+sum;
				sum=0;
			}
			if (give>=k)
				dem=i;
		}
	}

	cout<<dem<<"\n";
}

#include <iostream>
#include <math.h>
using namespace std;
int main() {
	int n, k, a, c = 0, d = 0, i;
	cin >> n >> k;
	for (i = 1; i <= n; i++) {
		cin >> a;
		a += c;
		if (a <= 8) {
			if (a < k)
			{
				k = k - a;
				c = 0;
			}
			else
			{
				if (d == 0)
					d = i;
				else d += 0;
			}
		}
		else {
			if (a < k) {
				k = k - 8;
				c = a - 8;
			}
			else {
				if (k <= 8) {
					if (d == 0)
						d = i;
					else d += 0;
				}
				else {
					k = k - 8;
					c = a - 8;
				}
			}
		}
	}
	if (d == 0)
		cout << "-1";
	else
		cout << d;
	return 0;
}

#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ll n,k,i,j,cnt=0,flag=0,sum=0,d=0,baran=0;
    cin >>n>>k;
    for(i=0;i<n;i++)
    {
        cin >>j;
        if(j<=8&&baran<k)
        {
             cnt++;
             if(sum>0)
             {
                 d=8-j;
                 if(d>sum)
                 {
                         d=sum;
                         sum=0;
                 }

             else
                sum-=d;
             }
             baran+=j+d;
             d=0;
        }
        else if(j>8&&baran<k)
        {
            cnt++;
            if(k-8>baran)
            baran+=8;
            else
                baran+=k-baran;
            sum+=j-8;
        }

    }
    if(baran<k)
        cout <<-1<<endl;
    else
    cout <<cnt<<endl;
    return 0;
}
//subtract from sum but not add with baran....what a newbie fact...

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,i,k,ar[1005],j;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    int to=0,l=0,m=0;
    for(j=0;j<n;j++)
    {
            to=ar[j]+to;
            if(to>8)
            {
                m=m+8;
                to=to-8;
            }
            else
            {
                m=m+to;
                to=0;
            }
            if(m>=k){l=1;break;}
    }
   if(l)cout<<j+1;
   else cout<<-1;

    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n, k, a, total = 0, count = 0;
	cin >> n;
	cin >> k;
	for (int i = 0; i < n && k > 0; i++) {
			cin >> a;
			total += a;
			if (total >=8) {
				k -= 8;
				total -= 8;
			}

			else {
				k -= total;
				total -= total;
			}
			count++;
	}
	if (k > 0 && n>0 ){
		cout << "-1";
	}
	else {
		cout << count;
	}
}

// God & me
// Fly ...
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 17;

int n, k, cur, ans;
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> k;
	while(n--){
		int x;
		cin >> x;
		cur += x;
		int r = min(8, cur);
		cur -= r;
		k -= r;
		ans++;
		if(k <= 0)
			break;
	}
	if(k > 0)
		cout << -1 << '\n';
	else
		cout << ans << '\n';
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int a, n, k, result = 0, left = 0;
	cin >> n >> k;

	for (int i = 1; i <= n; ++i)
	{
		cin >> a;
		a += left;
		if (a <= 8)
		{
			if (k > 0)
				result += 1;
			k -= a;
			left = 0;
		}
		else
		{
			if (k > 0)
				result += 1;
			k -= 8;
			left = a - 8;
		}
	}
	if (k > 0)
		cout << -1;
	else
		cout << result;
}

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int cal(int n, int k, int rem, int a[])
{

	for (int i = 1; i <= n; i++)
	{
		if (a[i] > 8 && rem >=8)
		{
			rem = rem - 8;
			a[i + 1] = a[i] - 8 + a[i + 1];
		}
		else
		{
			if (rem > a[i])
				rem = rem - a[i];
			else
				return i;
		}

		if (rem == 0)
			return i;
	}
	if (rem != 0)
		return -1;
}

void main()
{
	int k, rem,n;
	int a[102] = { 0 };

	cin >> n >> k;
	rem = k;

	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	cout << cal(n, k, rem, a);

}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=1;i<=n;i++)
	cin>>a[i];

	int j,r=k;
	int c=0;
	int days=0;
	for(j=1;j<=n;j++)
	{
		if(a[j]>8 && r>8)
		{
			r=r-8;
			a[j+1]=a[j+1]+(a[j]-8);
		}
		else if(r>=a[j])
		{
			r=r-a[j];
		}
		else if(r<a[j])
		{
			r=0;
		}
		if(r<=0)
		{
			cout<<j<<"\n";
			break;
		}
	}
	if(j>n)
		cout<<"-1\n";

	return 0;
}

#include<cstdio>
#include<cstdlib>
#define ll long long
const int N = 1e5 + 10;
using namespace std;
ll n, sum, sam, tg, k, a[N];
inline ll ckmn(ll a,ll b) {return a < b ? a : b;}
int main()
{
  scanf("%lld%lld",&n,&k);
  for(int i=1; i<=n; ++i) scanf("%lld",&a[i]);
  for(int i=1; i<=n; ++i)
  {
  	sam += a[i];
  	if(sam >= 8) sum += 8, sam -= 8; else sum += sam, sam = 0;
  	if(sum >= k) {tg = 1, printf("%d\n",i); break;}
  }
  if(!tg) printf("-1");
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n, k, temp, current, day;
	long long sum;
	vector<int> vec;

	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> temp;
		vec.push_back(temp);
	}
	current = sum = day = 0;
	for(int i = 0; i < n; i++){
		current += vec[i];
		day++;
		if(current <= 8){
			sum += current;
			current = 0;
		}
		else{
			sum += 8;
			current -= 8;
		}
		if(sum >= k) break;
	}
	if(sum >= k) cout << day << endl;
	else{
		cout << "-1" << endl;
	}

	return 0;
}

//Student ID:1751120
//Student Name:Nguyễn Trọng Tùng
//Ex 07
#include <iostream>
using namespace std;
int main()
{
	int n, k, m, i = 0, day = 0, b = 1, sum = 0;
	cin >> n >> k;
	while (i < n)
	{
		cin >> m;
		sum = sum + m;
		i++;
		if (k <= 8 && k > 0 && sum >= k)
		{
			b = 0;
			day++;
			k = 0;
			break;
		}
		if (m < 8 && sum <= 8)
		{
			k = k - sum;
			day++;
			sum = 0;
		}
		else
		{
			k = k - 8;
			sum = sum - 8;
			day++;
		}
	}
	if (b == 0)
		cout << day << endl;
	else
	{
		if (k != 0)
			cout << "-1" << endl;
		else
			cout << n << endl;
	}

}

#include<iostream>
using namespace std;
int main()
{
	int saving=0,n,k,a,S=0,d=0,test=0,d1;
	cin >> n>>k;
	for (int i = 1; i <= n; ++i)
	{
		cin >> a;
		++d;
		if (a >= 8)
		{
			saving += (a - 8);
			S += 8;
		}
		else
		{
			if (saving == 0)
			{
				S += a;
			}
			else
			{
				if ((saving + a) >= 8)
				{
					S += 8;
					saving -= (8 - a);
				}
				else if ((saving + a) < 8)
				{
					S += saving + a;
					saving = 0;
				}
			}
		}
		if ((S >= k) && (d < n))
		{
			d1= d;
			test = 1;
			S = -10000000000;
		}
	}
	if ((S >= k) && (d <= n) && (test != 1))
	{
		cout << d;
	}
	else if ((S < k)&&(test!=1))
		cout << "-1";
	else
		cout << d1;
	//system("pause");
	return 0;
}

#include<iostream>

using namespace std;
int main()
{
    int n;
    int k;
    cin >> n >> k;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int total=0;
    int j;
    for(j=0; j<n-1; j++)
    {
        if(arr[j] <= 8)
        {
            total = total + arr[j];
        }

        else
        {
            total = total + 8;
            arr[j+1] = arr[j+1]+arr[j]-8;
        }

        if(total >= k)
        {
            cout << j+1;
            return 0;
        }

    }

    if((total + arr[n-1] >= k) && (arr[n-1] <= 8))
    {
        cout<<n;
    }
    else if ((total + 8 >= k) && (arr[n-1] > 8))
    {
        cout<<n;
    }
    else
    {
        cout << -1;
    }

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
int a[10000];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        memset(a,0,sizeof(a));
        int sum = 0;
        for(int i = 0;i < n; i++)
        {
            scanf("%d",&a[i]);
            sum += a[i];
        }
        if(sum < k)
        {
            printf("-1\n");
            continue;
        }
        sum = 0;
        int ans;
        for(int i = 0; i < n; i++)
        {
            if(a[i] > 8)
            {
                if(i + 1 < n)
                a[i+1] += a[i] - 8;
                sum += 8;
            }
            else sum += a[i];
            if(sum >= k)
            {
                ans = i;
                break;
            }
        }
        if(sum < k)
        {
            printf("-1\n");
            continue;
        }
        printf("%d\n",ans+1);
    }
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        ans+=x;
        m-=min(ans,8);
        ans-=min(ans,8);
        if(m<=0)
            return !printf("%d\n",i);
    }
    return !printf("-1\n");
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main(){
	int n,m,a,sum,r,q;
	sum=0;
	r=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a;
		if (a<8){
			m=m-a;
			q=8-a;
			if(r>=q){
				m=m-q;
				r=r-q;
			}
			else{
				m=m-r;
				r=0;
			}
		}
		else {
			r=r+a-8;
			m=m-8;
		}
		if (m<=0&&sum==0){
			sum=i+1;
		}
	}

	if(sum!=0){
		cout<<sum;
	}
	else{
		cout<<-1;
	}
	return 0;
}

#include <iostream>
#include <string>

using namespace std;

void A839A() {
	int n, k;

	cin >> n >> k;

	int a,
		arya = 0,
		bran = 0,
		days = 0;

		for (int i = 0; i < n; i++)
		{
			cin >> a;

			arya += a;

			if (arya >= 8)
			{
				arya -= 8;
				bran += 8;
				days++;
			}
			else
			{
				bran += arya;
				arya = 0;
				days++;
			}
			if (bran >= k)
				break;
		}
		if (bran >= k)
			cout << days;
		else
			cout << "-1";

}

int main()
{
	//int endCheck;

	A839A();

	//cin >> endCheck;

	return 0;
}

//ID: 18127217
//Name: TRINH MINH THANH
//Ex07: 839A

#include <iostream>

using namespace std;

int main()
{
	int m, n, k, j;
	int count = 0;
	cin >> n;
	cin >> k;
	m = 0;
	j = 0;
	int S = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		if (m + j >= 8)
		{
			S = S + 8;
			j = j + m - 8;
			++count;
		}
		else if (m + j < 8)
		{
			S = S + m + j;
			j = 0;
			++count;
		}

		if (S >= k)
		{
			cout << count;
			return 0;
		}
	}
	if (S < k)
		cout << "-1";
	return 0;
}

#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int n, k;
	cin >> n >> k;
	int A[105];
	int have = 0;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < n; i++) {
		have += A[i];
		if (have >= 8) {
			if (k - 8 <= 0) {
				cout << i + 1 << endl;
				return 0;
			}
			else
			{
				k -= 8;
				have -= 8;
			}
		}
		else
		{
			if (k - have <= 0) {
				cout << i + 1 << endl;
				return 0;
			}
			else
			{
				k -= have;
				have = 0;
			}
		}
	}
	cout << -1;
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    long long n,k;
    cin>>n>>k;
    long long a[n],s=0;
    for (int i=0; i<n; i++)
    {
        cin>>a[i]; s+=a[i];
    }
    if (n*8<k) {cout<<-1; return 0;}
    long long q=0,ss=0;
    for (int i=0; i<n; i++)
    {
        a[i]+=q;
        if (a[i]>=8) {ss+=8; q=a[i]-8;} else {ss+=a[i]; q=0;}
        if (ss>=k) {cout<<i+1; return 0;}
    }
    cout<<-1;

    return 0;

}

#include <iostream>
#include <iostream>
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main() {

  int n, k;
  int storage = 0;
  int bruh = 0;
  int given = 0;
  int days = 0;

  cin >> n >> k;

  while(n--){
    int ai;
    cin >> ai;
    storage+=ai;
    int minimum = min(8, storage);
    given+= minimum;
    storage-=minimum;

    days++;
    if(given>=k){
     break;
    }
  }
  if(given<k){
    days = -1;
  }
  cout << days << endl;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
  #ifdef Zonda_R
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
  #endif
  int sum = 0, n, k;
  scanf("%d %d", &n, &k);
  for(int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    sum += x;
    k -= min(sum, 8);
    sum -= min(sum, 8);
    if(k <= 0) {
      printf("%d\n", i + 1);
      return 0;
    }
  }
  puts("-1");
  return 0;
}

#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>

using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> candies;
	for(int i=0;i<n;++i){
		int c;
		cin>>c;
		candies.push_back(c);
	}
	int curr=0;
	for(int i=0;i<candies.size();++i){
		int x = candies[i] + curr;

		//cout<<x<<" "<<k<<endl;

		if(x>8){
			k-=8;
			curr=x-8;

		}
		else{
			k-=x;
			curr=0;

		}
		if(k<=0){
			cout<<i+1;
			break;
		}
	}

	if(k>0){
		cout<<-1;
	}

}

#include <cstdio>
int n,k,now,ans;
int main(){
    scanf ("%d%d",&n,&k);
    int i=1;
    for (;i<=n;i++){
        int a;
        scanf ("%d",&a);
        if (a>8)ans+=8,now+=a-8;
        else if (a<=8&&!now)ans+=a;
        else if (now+a<=8)ans+=now+a,now=0;
        else ans+=8,now-=8-a;
        if (ans>=k)break;
    }
    if (i>n&&ans<k)printf ("-1");
    else printf ("%d",i);
}

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 105;

int n, k;
int a[N];

int main() {
    cin >> n >> k;

    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);

    int s = 0, last_num = 0;
    for (int i = 0; i < n; i++) {
        int cur = last_num + a[i];
        s += min(cur, 8);

        if (s >= k) {
            cout << i + 1 << endl;
            return 0;
        }
        last_num = cur - min(cur, 8);
    }

    cout << "-1" << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;

	int a = 0, b = 0, d = 0;
	for (int i = 0; i < n; ++i) {
		int c;
		cin >> c;

		if (c + a >= 8) {
			b += 8;
			a += c - 8;
			++d;
		}
		else {
			b += c + a;
			a = 0;
			++d;
		}

		if (b >= k) {
			cout << d;
			return 0;
		}
	}

	if (b < k) {
		cout << -1;
	}
	return 0;
}

#include <bits/stdc++.h>

int main() {

    //input
    int n, k;
    scanf("%d %d",&n,&k);
    int arr[n];
    for (int i = 0; i < n; i++) {
        scanf("%d",&arr[i]);
    }

    // data processing(algorithm)
    int candies = 0, reserves = 0, days = 0;
    bool achieved = false;

    for (int i = 0; i<n; i++) {
        int a = 0;
        a = arr[i];

        if (a >= 8) {
            int reservese = a - 8;
            reserves += reservese;
            candies += 8;
            days += 1;
        }

        else{
            candies += a;

            if (reserves > 0) {
                int many = 8 - a;
                if (many >= reserves) {
                    candies += reserves;
                    reserves = 0;
                }
                else {
                    candies += many;
                    reserves -= many;
                }
            }
            days += 1;
        }

        if (candies >= k) {
            achieved = true;
            break;
        }

    }

    // output
        if (achieved) {
            printf("%d",days);
        }
        else {
            printf("-1");
        }

}

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, k, i, c = 0;
    scanf("%d %d", &n, &k);
    int a[n];
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) {
        if (a[i] > 8) {
            int tmp = a[i] - 8;
            a[i] = 8;
            a[i + 1] += tmp;
        }
        k -= a[i];
        if (k <= 0) {
            printf("%d\n", c + 1);
            return 0;
        }
        else c++;
    }
    puts("-1");
    return 0;
}

//ID: 18127217
//Name: TRINH MINH THANH
//Ex07: 839A

#include <iostream>

using namespace std;

int main()
{
	int n, k, m, j;
	int count = 0;
	cin >> n;
	cin >> k;
	m = 0;
	j = 0;
	int S = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> m;
		if (m + j >= 8)
		{
			S = S + 8;
			j = j + m - 8;
			++count;
		}
		else if (m + j < 8)
		{
			S = S + m + j;
			j = 0;
			++count;
		}

		if (S >= k)
		{
			cout << count;
			return 0;
		}
	}
	if (S < k)
		cout << "-1";
	return 0;
}

#include<cstdio>
#include<iostream>
using namespace std;

int a[101];
int main() {
	int n, k, sum = 0;
	int i, flag = 0, remin = 0;
	scanf("%d %d", &n, &k);//{
		for (i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
			if (a[i]+remin > 8) {
				remin += a[i] - 8;
				sum += 8;
			}
			else {
				sum += a[i] + remin;
				remin = 0;
			}
			if (sum >= k) {
				flag = 1;  break;
			}
		//	printf("%d %d %d\n",i, sum, remin);
		}
		if (flag) printf("%d\n", i);
		else printf("-1\n");
	//}
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int days, candies;
	cin >> days >> candies;
	int sum = 0;
	for (int i = 0; i < days; i++)
	{
		int temp;
		cin >> temp;
		if (temp > 8)
		{
			candies -= 8;
			temp -= 8;
		}
		else
		{
			if (sum + temp > 8)
			{
				candies -= 8;
				sum -= 8;
			}
			else
			{
				candies -= temp;
				candies -= sum;
				temp = 0;
				sum = 0;
			}
		}
		sum += temp;
		if (candies <= 0)
		{
			cout << i + 1 << endl;
			return 0;
		}
	}
	if (candies <= 0)
	{
		cout << days << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}

# include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int a[1000];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}

	int extra=0;
	int sum = 0;
	int ans = -1;
	for(int i=0;i<n;i++)
	{
		if(a[i] > 8)
		{
			extra += a[i]-8;
			a[i] = 8;
		}

		else if(a[i] < 8)
		{
			int prev = a[i];
			a[i] = min(8, a[i]+extra);
			extra -= (a[i]-prev);
		}

		sum += a[i];
		if(sum >=k)
		{
			ans = i+1;
			break;
		}

	}
	cout << ans << '\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,k,a[110],ans=0,num=0,flag=0;

int main()
{   cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    for(int i=1;i<=n;++i)
    {
        a[i]+=num;
        num=max(0,a[i]-8);
        ans+=min(8,a[i]);
        if(ans>=k && !flag)
            cout<<i<<endl,flag=1;
    }
    if(flag==0)
        cout<<-1<<endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <utility>
#include <map>
#include <queue>
#include <iterator>
using namespace std;

int main() {
	int n, k; cin >> n >> k;
	int summ = 0;
	int b = 0;
	for (int i = 1; i <= n; i++) {
		int temp; cin >> temp;
		summ += temp;
		b += min(summ, 8);
		summ -= min(summ, 8);
		if (b >= k) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return 0;
}

#include <iostream>

int main() {
	int n, k;
	std::cin >> n >> k;
	int totalg = 0;
	int has = 0;
	int days = 0;

	for (int i = 0; i < n; i++) {
		days++;
		int s;
		std::cin >> s;
		has += s;
		if (has >= 8) {
			has -= 8;
			totalg += 8;
		}
		else if (has > 0) {
			totalg += has;
			has = 0;
		}
		if (totalg >= k) {
			std::cout << days;
			return 0;
		}
	}
	if (totalg < k) {
		std::cout << -1;
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long sum,t,d,q;
bool z=0;
#define beshoo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    beshoo
    int n,k;cin>>n>>k;int arr[n];
    for (int i=0;i<n;i++){cin>>arr[i];sum+=arr[i];}
    if(sum<k){cout<<-1;return 0;}
    for(int i=0;i<n;i++){
        if(i!=n-1){
            if(arr[i]>8){
                t+=8;
                arr[i+1]+=arr[i]-8;
    }
            else{t+=arr[i];}
    }
    else{
            if(arr[i]>8){
                t+=8;
    }
            else{t+=arr[i];}

    }
            if(t>=k){d=i;break;}
    }
    if(t<k)cout<<-1;
    else cout<<d+1;

    return 0;
}

//19125099
//Duong Van Khoa
//19CTT1

//Test case 1:
//Input: 3 4
//       3 3 3
//Output: 2

//Test case 1:
//Input: 2 10
//       8 8
//Output: 2

//Test case 1:
//Input: 4 9
//       1 2 3 4
//Output: 4
#include<iostream>
using namespace std;
int main()
{
	int days, candyneed, numbersperday = 0, b = 0, numberofcandy = 0;
	cin >> days; cin >> candyneed;
	for (int i = 0; i < days; i++)
	{
		cin >> numbersperday;  numbersperday += b;
		if (numbersperday > 7) {
			numberofcandy += 8; b = numbersperday - 8;
		}
		else {
			numberofcandy += numbersperday; b = 0;
		}
		if (numberofcandy >= candyneed) {
			cout << i + 1;
			return 0;
		}
	}
	cout << "-1";
	return 0;
}

#include <iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>

#define mod 1000000007
#define pa(a,b) make_pair(a,b)
#define f first
#define s second
#define pb(a)  push_back(a)
#define all(a) a.begin() , a.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define LL  long long int

LL maxx(LL a , LL b){ return a>b ?  a : b ;}
LL minn(LL a , LL b){ return a>b ?  b : a ;}

using namespace std;
LL gcd(LL a, LL b) {
    return b == 0 ? a : gcd(b, a % b);
}
LL lcm(LL a , LL b )
{
    return (a*b)/gcd(a , b);
}
int main()
{
    int n,k;
    cin>>n>>k; int sum=0,s=0;
    for(int i=0;i<n;i++)
    {
        int a; cin>>a;
        sum+=min(a+s,8); if(a<8)s-=min(s,8-a); a-=min(a,8); s+=a;
        if(sum>=k)return cout<<i+1 , 0;
    }
    cout<<-1;
}

#include <iostream>
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

const ll INF = 1e18 + 1;
const ll N = 1e5;
const ll MOD = 1e18 + 1;

using namespace std;

vector<ll> b;
vector< vector<ll> > g(N + 5);
ll n, m, k, r, x, y, l, c, t, cur, ans, mn(INF), mx(-INF), a[N + 5];
char c1, c2;
string s;
bool f, fl, used[N + 5];

void read(ll &in)
{
    scanf("%I64d", &in);
}

void read(ll &in1, ll &in2)
{
    scanf("%I64d%I64d", &in1, &in2);
}
void read(ll &in1, ll &in2, ll &in3)
{
    scanf("%I64d%I64d%I64d", &in1, &in2, &in3);
}
int main()
{
    //ios_base::sync_with_stdio(0);
    //cin.tie(0);
    read(n, k);
    for(int i = 0; i < n; i++)
    {
        read(c);
        cur += c;
        if(cur <= 8)
        {
            k -= cur;
            cur = 0;
        }
        else
        {
            k -= 8;
            cur -= 8;
        }
        if(k <= 0)
        {
            cout << i + 1;
            return 0;
        }
    }
    cout << -1;
    return 0;
}

#include<cstdio>
#include<iostream>
using namespace std;
int x,n,k,now,b;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&x);
		b+=x;
		now+=min(b,8);
		b-=min(b,8);
		if(now>=k)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
}

#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include <complex>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<algorithm>
#include <cassert>
#include <stack>
#include<cstring>
#include <cmath>
#include <complex>
#include <sstream>
#include<cstring>
#include <complex>
#include<cstdlib>
#include <set>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <cstdio>
#include<map>
#include <vector>
#include <iostream>
using namespace std;

#define start          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nl            endl;
#define end            system("pause");
#define sz(v)            ((int)((v).size()))
#define sc(x)            scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define sc3(x,y,z)       scanf("%d%d%d",&x,&y,&z)
#define sc4(x,y,z,a)     scanf("%d%d%d%d",&x,&y,&z,&a)
#define sc5(x,y,z,a,b)   scanf("%d%d%d%d%d",&x,&y,&z,&a,&b)
#define sc6(x,y,z,a,b,c) scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c)
#define scl(x)           scanf("%lld",&x)
#define lp(i,n)        for(int i=0;i<n;i++)
#define lp1(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define PI           acos(-1)
#define INF             1<<30
typedef string            S;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<S, int>     si;
typedef pair<int, S>     is;
typedef pair<char, int>  chi;
typedef pair<S, S>       SS;
typedef vector<ii>        vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<S>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;

ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }

int main()
{
	start;
	int n,k,a,ans=0,l=0;
	cin>>n>>k;
	lp1(i,1,n+1)
	{
		cin>>a;
		a+=l;
		if(a<=8)
		{
			if(l>=a)
				l-=a;
			else
				l=0;
			ans++;
			k-=a;
		}
		else
		{
			l=a-8;
			ans++;
			k-=8;
		}
		if(k<=0)
		{
			break;
		}
	}
	if(k<=0&&ans<=n)
		cout<<ans<<endl;
	else
		cout<<-1<<endl;
	//end;
}

#include <cstdio>
int n,k,now,ans;
int main(void){
    scanf ("%d%d",&n,&k);
    int i=1;
    for (;i<=n;i++){
        int a;
        scanf ("%d",&a);
        if (a>8)ans+=8,now+=a-8;
        else if (a<=8&&!now)ans+=a;
        else if (now+a<=8)ans+=now+a,now=0;
        else ans+=8,now-=8-a;
        if (ans>=k)break;
    }
    if (i>n&&ans<k)printf ("-1");
    else printf ("%d",i);
    return 0;
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.

    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.

    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.

    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.

    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.

    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
    //that's the end of the program.
}

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define ep emplace_back
#define mp make_pair
#define ll long long
#define F first
#define S second

int a[111];
int main(void)
{
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	/*
	int sum = accumulate(a+1, a+1+n, 0);
	if (sum < k)
	{
		printf("-1\n");
		return 0;
	}
	*/
	int ans=0, rem=0;

	for (int i=1; i<=n; i++)
	{
		rem += a[i];
		//else rem += a[i];
		int tmp = rem >= 9 ? 8 : rem;

		ans += tmp;
		rem -= tmp;

		//rem += a[i] >= 9 ? a[i]-8 : 0;
		//printf("i:%d, sum:%d, rem:%d\n", i, ans, rem);
		if (ans >= k)
		{
			printf("%d\n", i);
			return 0;
		}
	}
	printf("-1\n");

	return 0;
}

#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <climits>

using namespace std;

int main()
{
	int n,k;
	cin>>n>>k;
	vector<int> candies;
	for(int i=0;i<n;++i){
		int c;
		cin>>c;
		candies.push_back(c);
	}
	int curr=0;
	for(int i=0;i<candies.size();++i){
		int x = candies[i] + curr;
		//cout<<x<<" "<<k<<endl;

		if(x>8){
			k-=8;
			curr=x-8;

		}
		else{
			k-=x;

		}
		if(k<=0){
			cout<<i+1;
			break;
		}
	}

	if(k>0){
		cout<<-1;
	}

}

#include <iostream>

using namespace std;

int main()
{
	int t,k1;

	cin >> t >> k1;
	int day= 0,reste=0,a,somme = 0;
	int k = k1;
	while(t--)
	{

		if(k <=0)

			break;

		cin >> a;

		somme += a;
		a += reste;

		if(a <=8)
			k -= a;
		else
		{

			k-=8;
			reste = a - 8;
		}
		day++;

	}

	if (somme < k1 || k>0)
		cout << "-1";
	else
		cout << day;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int sum = 0;
    int n,k,i;
    cin >> n >> k ;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>8){sum = sum + 8;a[i+1] = a[i]-8+a[i+1];}else{
            sum = sum + a[i];
        }
    }

    if(sum<k){cout << ("-1");}else{cout << i;}

    return 0;
}

#include <cstdio>
int main()
{
    int a[11000];
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    int flag=0;
    int sum=0,ff=0;
    for(int i=0; i<n; i++)
    {
        int b=a[i];
        a[i]+=flag;
        if(a[i]>8)
        {
            //flag=a[i]-8;
            a[i]=8;
        }
        if(b>8)
            flag=b-8;
        else flag=0;
        sum+=a[i];
        if(sum>=m)
        {
            printf("%d\n",i+1);
            ff=1;
            break;
        }
    }
    if(ff==0)
        printf("-1\n");
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
	int day, gv, left,a, htg, en=0, s = -1,p=1,m,n;
	cin >> day >> htg;
	for (int i = 1; i <= day; i++)
	{
		cin >> gv;
		en += gv;
	}
	if (en < htg)
		cout << s;
	else
	{
		left = (int)en / 8;
		a = en % 8;
		cout << left;
		if (left >= day)
		{
			left = day;
			if (left * 8 >= htg)
				cout << left;
			else
				cout << s;
		}
		else
		{
			if (left==0)
			{
			left = 1;
			if (left * 8 + a >= htg)
			{
				left++;
				cout << left;
			}
			else
				cout << s;
			}
			else
			{
				m = (left * 8) + a;
				if (m >= htg) {
					left++;
					cout << left;
				}
				else {
					cout << s;
				}
			}

		}
	}
	return 0;
}

# include <bits/stdc++.h>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int a[1000];
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
	}

	int sum =0;
	int ans = -1;
	for(int i=0;i<n;i++)
	{

		sum += min(8, a[i]);
		if(sum >= k)
		{
			ans = i+1;
			break;
		}

	}

	cout << ans << '\n';
	return 0;
}

#include <iostream>
#include<bits/stdc++.h>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
int n,k;
cin>>n>>k;
int arr[n];
int sum1=0;
for(int i=0;i<n;i++)
{
cin>>arr[i];
sum1+=arr[i];
}
int sum=0;
int counter=0;
for(int i=0;i<n;i++)
{
    if(k<=0){
        break;
    }
    if(arr[i]+sum>8){
        sum+=arr[i]-8;
        k=k-8;
    }
    else{
        k-=arr[i]+sum;
        sum=sum-(8-arr[i]);
    }
    counter++;

//cout<<k<<endl;
}
//cout<<k<<endl;
if(k>0){
    cout<<-1;
}
else
cout<<counter;

    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

void abc()
{
      int n, k, t = 0, i, b, sum = 0;
	cin >> n >> k;
	vector<int> v;

	for(i = 0; i < n; i++)
	{
		cin >> b;
		v.push_back(b);
	}

	for(auto i : v)
		sum += i;

	if(sum < k)
	{
		cout << "-1";
		return;
	}
	if((k/n) > 8)
	{
		cout << "-1";
		return;
	}
	sum = 0;
	while(sum < k)
	{
		if(v[t] <= 8)
			sum += v[t];
		else
		{
			if(t != (n - 1))
			{
				sum += 8;
				v[t+1] += (v[t] - 8);
			}
			else sum += v[t];
		}
		t++;
	}
	cout << t;
	return;
}

int main()
{
	abc();
}

#include<iostream>
using namespace std;
int main ()
{
	int n,k,i,a,sum;
	cin >> n;
	cin >> k;
	i=1;
	sum=0;
	while (i<=n)
	{
	  cin >> a;
	  ++i;
	  if (n==1 && k>8 && (a<8 || a>8))
		  break;
	  if (a>=8)
	     sum= sum + 8;
	  else if (a<8)
		      sum =sum+a;
	   if (sum >=k)
		   break;
	  }
	if (sum < 1 || sum <k) cout << "-1" << endl;
	if (sum > 0 && sum >=k) cout << --i << endl;
	if (sum > 0 && sum >=k && i<n) cout << i << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

/*int f(int a) {
	int h=0;
	while (a > 0) {
		h = h * 10 + a % 10;
		a /= 10;
	}
	return h;
}*/

/*int main() {
	int a;

	/*cout << typeid(v).name();*/
	/*cout << "Enter the number:";
	cin >> a;
    string v=to_string(a);
	string copy(v);
	reverse(copy.begin(), copy.end());
	cout << v << endl << copy << endl;
	system("pause");
	return 0;
}*/

/*int main() {  /// двоичный протокол
	int len;
	cin >> len;
	string p;
	cin >> p;
	int otv=0;
	int step=0;
	for (int i = len - 1; i >= 0;--i) {
		if (p[i] == '0') {
			while (p[i] == '0') {
				step+=1;
				--i;
			}
		}
		else {
			int h = 0;
			while (i>=0&&p[i] == '1') {
				++h;
				--i;
			}
			otv += h*pow(10, step);
		}
		++i;
	}
	cout << otv << endl;
	system("pause");
	return 0;
}*/

/*void f(int *a, int *b, int n) { // способ 1 мемори и вороны
	int res = 0;
	bool ok = 1;
	for (int i = n - 1; i >= 0; --i) {
		for (int g = i+1; g <n; ++g) {
			if (ok) {
				res += b[g];
				ok = 0;
		    }
			else {
				res -= b[g];
				ok = 1;
			}
		}
		res += a[i];
		b[i] = res;
		res = 0; ok = 1;
	}
	for (int k = 0; k < n;++k) {
		cout << b[k] << ' ';
	}
	cout << endl;
}*/

/*void f(int *a, int *b, int n) { //способ 2 мемори и вороны
	int i = n - 1;
	b[i] = a[i];
	for (i-=1; i >= 0;--i) {
		b[i] = a[i] + a[i + 1];
	}
	for (int h = 0; h < n;++h) {
		cout << b[h] << ' ';
	}
	cout << endl;
}*/

/*int main() { ///мемори и вороны
	int n;cin >> n;
	int *a= new int [n];
	int *b = new int[n];
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	f(a, b, n);
	delete a;
	delete b;
	system("pause");
	return 0;
}*/

/*int main() {
	int n; cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	system("pause");
	return 0;
}*/

int main() {
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	int i;
	int sum=0;
	for (i = 0; i < n; ++i)
		cin >> a[i];
	for (i = 0; i < n-1; ++i) {
		if (a[i] > 8) {
			sum += 8; a[i + 1] += a[i] - 8;
		}
		else sum += a[i];
		if (sum >= k) {
			cout << i+1 << endl;
			/*system("pause");*/
			return 0;
		}
	}
	if (sum < k) cout << "-1" << endl;
	/*system("pause")*/
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
int sum=0,p=0;
  for(int i=0;i<n;i++)
  {
     int a;
      cin>>a;
      if(a<8)
      {sum+=a;p++;}
      else
      {
          sum+=8;
        p++;
      }
      if(sum>=k)
      {cout<<p;break;}
  }
   if(sum<k)
   {
     cout<<-1;
   }

  return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
    int n,k,i,a,t,sum;
	while(~scanf("%d%d",&n,&k))
	{
		t=0;sum=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a);
			if(a<=8&&(sum<k))
			{
				t++;sum+=a;
			}
			else if(a>8&&(sum<k))
			{
				t++;sum+=8;
			}
		}
		if(k>sum)
		{
			printf("-1\n");
		}
		else
		{
			printf("%d\n",t);
		}

	}
    return 0;
}

//https://codeforces.com/problemset/problem/839/A
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
ll mod = 1e9 + 7;

int main ()
{
	ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
	int n, k, d = 0, cur = 0;
	cin >> n >> k;
	int arr[n];
	for (auto& elem : arr)
	{
		cin >> elem;
	}
	sort (arr, arr + n, greater<int> ());
	for (int i = 0; i < n && k > 0; ++i)
	{
		cur += arr[i];
		int r = min (cur, 8);
		k -= r;
		cur -= r;
		d++;
	}
	if (k > 0)
		cout << -1;
	else
		cout << d;
}

#include<iostream>
using namespace std;
int main()
{
	int n,k,i;
	int gun = 0;
	cin >> n >> k;
	int a[n];
	int sum = 0;
	for(i = 0 ; i < n ; i++)
	{
		cin >> a[i];
		sum+=a[i];
	}
	if(k > n*8 || sum < k)
	cout << "-1";
	else
	{
		i=0;
		int artiqqalan = 0;
		int catismayan;
		while(k>0 || i<n)
		{
			if(a[i]>=8)
			{
			k-=8;
		    artiqqalan+=a[i]-8;
			}
			else{
			catismayan = 8 - a[i];
			if(artiqqalan >= catismayan)
			{
				a[i] = 8;
				artiqqalan-=catismayan;
				k-=a[i];
			}
			else if(artiqqalan > 0)
			{
				artiqqalan = 0;
				a[i]+=artiqqalan;
				k-=a[i];
			}
			else k-=a[i];
			}
			i++;
			gun++;
		}
		cout << gun;
	}
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a , b;
	cin >> a >>  b;
	int x[a];
	for(int i=0 ; i<a  ; i++)
	{
		cin >> x[i];
	}
	for(int i=0 ; i<1000000 ; i++)
	{
		if(x[i]<=8)
		{
			b=b-x[i];
		}
		if(x[i]>8)
		{
			b=b-8;
		}
		if(b<=0){
			cout<<i+1;
			return 0;
		}
	}
	cout<<"-1";
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[50000],i,j,sum=0,cnt=0;
    cin>>n>>k;
    for(i=0;i<n;i++)cin>>a[i];
    for(i=0;i<n;i++)
    {
        if(a[i]<=8)
        {
            sum+=a[i];
            cnt++;
        }
        else if(a[i]>8)
        {
            sum+=8;
            cnt++;
        }
        if(sum>=k)
        {
            cout<<cnt<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}

#include<stdio.h>
#include<string.h>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long long k;
    int a[110];
    while(~scanf("%d%lld",&n,&k))
    {
        long long sum=0,ans=0,x;
        for(int i=0;i<n;i++)
        {
            scanf("%lld",&x);
            sum+=x;
            if(sum>=8)
            {
                sum-=8;
                k-=8;
            }
            else
            {
                sum-=x;
                k-=x;
            }
            if(k<=0&&ans!=0)
            {
                ans=i+1;
            }
        }
        if(ans!=0)
        printf("%lld\n",ans);
        else
        printf("-1\n");
    }
    return 0;
}

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 110;

int a[maxn];

int main()
{
//  freopen("input.txt","r",stdin);
//  ios::sync_with_stdio(false); cin.tie(0);
    int n,ans=-1;
	ll k,tem1=0,tem2=0;
	memset(a,0,sizeof(a));
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
    	scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		tem2+=a[i];
		if(tem2<=8){
			tem1+=tem2;
			tem2=0;
		}
		else{
			tem1+=8;
			tem2-=8;
		}
//		cout<<tem1<<" "<<tem2<<endl;
		if(tem1>=k){
			ans=i;break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

/*.........................................
       .   *BISMILLAHIR RAHMANIR RAHIM*   .
       .       [ALLAH] is Almighty        .
       ....................................
 ********************************************
 *   . . . . . . . . . . . . . . . . . ..   *
 *   .  solved_by: zitul_mahmud;        .   *
 *   .  Applied_physics_electronics     .   *
 *   .  & communication_engineering;    .   *
 *   .  Islamic university,kushtia;     .   *
 *   .  zitulmahmud88@gmail.com;        .   *
 *   .  "STAY HUNGRY STAY FOOLISH"      .   *
 *   . . . . . . . . . . . . . . . . . ..   *
 ********************************************/

# include<sstream>
# include<string.h>
# include<bits/stdc++.h>

typedef long long ll;
typedef double    dl;
using namespace   std;

# define PI            2*acos(0.0)
# define MOD           100000007
# define sz            100005/*array_size*/
# define FF            first
# define SS            second
# define PB            push_back
# define MP            make_pair/*make_pair()*/
# define clr(x)        (x).clear()
# define all(x)        (x).begin(),(x).end() /*sorting STL */
# define MEM(a)        memset(ara,true,sizeof(ara));

/*Input section*/
# define si(a) scanf("%d",&a)
# define sii(a,b) scanf("%d %d",&a,&b)
# define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)

# define sl(a) scanf("%lld",&a);
# define sll(a,b) scanf("%lld %lld",&a,&b);
# define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);

#define FR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define FRR(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)

#define fr(i,a,b) for(int i=a;i<(int)b;i++)
#define frr(i,a,b) for(int i=a;i<=(int)b;i++)

///Output section
# define SP printf(" ")
# define NL printf("\n")
# define CH getchar()
# define DB printf("I AM HERE\n")
# define open freopen("input.txt","r",stdin)
# define close freopen("output.txt","w",stdout)
# define FAST ios_base::sync_with_stdio(0),cin.tie(0)

///output for int data type
# define pi(a) printf("%d\n",a)
# define pii(a,b) printf("%d %d\n",a,b)
# define piii(a,b,c) printf("%d %d %d\n",a,b,c)

///output for ll data type
void pl(ll a){printf("%lld\n",a);}
void pll(ll a,ll b){printf("%lld %lld\n",a,b);}
void plll(ll a,ll b,ll c){printf("%lld %lld %lld ",a,b,c);}

# define LB(x,p) lower_bound(all(x),p)-(x).begin()
# define UB(x,p) upper_bound(all(x),p)-(x).begin()
# define IT(it,c) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)

void sss(string s)           {cout<<s,NL;}
ll string_to_ll(string s)    {stringstream ss;ss<<s;ll n;ss>>n;return n;}
string ll_to_string(ll n)    {stringstream ss;ss<<n;string s;ss>>s;return s;}

/*********************************************************************************
 *                 ###############################                               *
 *                 #  [ END OF ALL DECLARATION ] #                               *
 *                 ###############################                               *
 *********************************************************************************/

              /*STARTING OF MAIN FUNCTION*/

int main()
{
        int n,ara[sz/1000],k;
        sii(n,k);
        fr(i,0,n) si(ara[i]);
        int res,total=0;
        fr(i,0,n)
        {
               int aa=ara[i]+res;
               if(aa>8)
               {
                      total+=8;
                      res+=(ara[i]-8);
               }
               else total+=aa;
               if(total>=k)
               {
                      pi(i+1);
                      return 0;
               }
        }
        pi(-1);
        return 0;
}

              /*Anyone who has never made a mistake has never tried anything new.
                             [ ~SIR ALBERT EINSTINE~ ]*/

#include <bits/stdc++.h>

using namespace std;

int main()
{

   int n,k;
   cin>>n>>k;
   int a[n],i,sum=0;
   for(i=0;i<n;++i)
       cin>>a[i];

    for(i=0;i<n;++i)
      {

          if(k==0)
            {
               break;
            }

         else if(a[i]<=k)
            {
                if(a[i]>8)
                   { k=k-8;
                     sum+=a[i]-8;
                   }

                else
                  {
                      if(sum>=(8-a[i]))
                          {
                              k=k-8;
                              sum=sum-(8-a[i]);
                          }

                     else
                       k=k-a[i];
                  }
            }

           else
            {
               if(k>8)
                  k=k-8;

                else
                  k=0;
            }

            if(sum>=k)
              {
                  k=k-sum;
                  sum=0;
              }
      }

      if(k!=0)
         cout<<"-1";

      else
        cout<<i;

    return 0;

}

#include <iostream>
using namespace std;
int main()
{
	int n, k, *a,day=0;
	cin >> n >> k;
	a = new int[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i]>8)
			k -= 8;
		else
			k -= a[i];
		day++;
		if (k <= 0)
			break;
	}
	cout << (k > 0 ? -1 : day);
	return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <hash_map>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int main() {
	PLAY();

	int n, k;
	cin >> n >> k;
	if (k > 8 * n) {
		cout << -1 << endl;
		return 0;
	}
	int e = 0, res = -1;
	for (int i = 1; i <= n; i++){
		int x; cin >> x;
		if (x >= 8) {
			e += x - 8;
			k -= 8;
		}
		else {
			x += e;
			if (x >= 8)  {
				e += x - 8;
				k -= 8;
			}
			else k -= x;
		}
		if (k <= 0) {
			res = i;
			break;
		}
	}

	cout << res << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pp pop_back
#define mp make_pair
#define F first
#define S second
#define Need_for_speed 	ios_base::sync_with_stdio(0);
//cout<<fixed<<setprecision()
int main(){
	Need_for_speed;
	int n,m,sum=0,ans=0,num;
	cin>>n>>m;
	int a[n];
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	for(int i = 1; i <= n; i++){
		if(a[i] <= 8){
			sum+=a[i];
			if(num + a[i] > 8){
				sum+=8-a[i];
				num=num-8-a[i];
			}
			ans++;
		}
		else{
			sum+=8;
			num+=a[i]-8;
			ans++;
		}
		if(sum >= m){
			cout<<ans;
			return 0;
		}
	}
	cout<<"-1";
}

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int n,k,cnt=0;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    if(a[i]>=8) {k-=8; cnt+=a[i]-8;}
    else if(cnt>a[i]) {cnt+=a[i]; if(cnt>8){k-=8; cnt-=8;} else{ k-=cnt; cnt=0;}}
    if(k<=0) {cout<<i+1; return 0;}
  }
  cout<<-1;
  return 0;
}

// In the name of ALlah //
#include<iostream>
using namespace std;
int main()
{
	int n,k,x,sum = 0,sum1 = 0,ans  =0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		if (x > 8)
		{
			while (x > 8)
			{
				x -= 8;
				sum += 8;
				ans ++;
				if (sum >= k)
				{
					cout << ans;
					return 0;
				}
			}
		}
		else if (x <= 8 && x != 0)
		{
			sum1 += x;
		}
	}
	ans += (sum1/8)+(sum1%8);
	if (sum1 + sum >= k)
	{
		cout << ans;
		return 0;
	}

	cout << -1;

	return 0;
}

#include <iostream>

using namespace std;

int main() {
	int n,k;
	int sum=0,bum=0;
	int  s[105];
	cin >> n >> k;
	if (k>n*8)
	{
		cout << -1;
		return 0;
	}
	if (k==n*8)
	{
		cout << n;
		return 0;
	}
	for (int i=0; i<n; i++)
	{
		cin >> s[i];
	}
	for (int i=0; i<n; i++)
	{
		sum+=s[i];
		if (sum>=k&&sum>8*i)
		{
			cout << i+2;
			return 0;
		}
		else if (sum>=k&&sum<=8*i)
		{
			cout << i+1;
			return 0;
		}
	}
	cout << -1;
	return 0;
}

//Name: Ngo Van Phat
//ID: 1753082
//Ex07
#include <iostream>
using namespace std;
int main()
{
	int day, candy, give;
	cin >> day;
	cin >> candy;
	int s = 0;
	for (int i = 1; i <= day; i++)
	{
		cin >> give;
		s = s + give;
			}

	if (day==1&&s>candy) cout << "-1" << endl;
	else if (candy <= s) cout << day << endl;
	else if (candy > s) cout << -1 << endl;
	//system("pause");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,candies,days=0,sum=0,i,x;
    vector<int> a;
    cin >> n >>k;
    for (i = 0; i < n; ++i)
    {
    	/* code */
    	cin >> x;
    	a.push_back(x);
    	sum+=x;
    }
    a.push_back(0);
    if(sum<k)
    	cout << -1;

    else
    {
    	for (i = 0; i < n; ++i)
    	{
    		/* code */
    		if(candies>=k)
    			break;
    		if(a[i]<=8)
    			candies+=a[i];
    		else
    		{
    			candies+=8;
    			a[i+1]+=a[i]-8;
    		}
    	}
    }
    if(candies>=k)
    	cout << i;
    else
    	cout << -1;

}

#include<iostream>
#include<string>
using namespace std;

int min(int a, int b)
{
	if (a > b)
		return b;
	else
		return a;

}

int main()
{
	int n;

	cin >> n;

		int k;
		cin >> k;

		int*a = new int[n];
		for (int i = 0; i <= n -1; i++)
			cin >> a[i];

		int s = 0;
		int b = 0;
		int i = 0;
		bool f = true;
		while (b<k)
		{
			if (i > n - 1)
			{
				f = false;
				break;
			}
			b += min(s+a[i], 8);
			if (a[i] > 8)
			{s += a[i] - 8;
			}

			i++;
		}

		if (f == false)
			cout << -1 << endl;
		else
		cout << i <<endl;

		delete[] a;

	return 0;
}

#include<stdio.h>
#include<string.h>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    int a[110];
    while(~scanf("%d%d",&n,&k))
    {
        int sum=0,ans=0,x;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            sum+=x;
            if(sum>=8)
            {
                sum-=8;
                k-=8;
            }
            else
            {
                sum-=x;
                k-=x;
            }
            if(k>=0&&ans!=0)
            {
                ans=i+1;
            }
        }
        if(ans!=0)
        printf("%d\n",ans);
        else
        printf("-1\n");
    }
    return 0;
}

#include <stdio.h>

int main()
{
	int n,k,i,j,t;
	int a[110]; int flag=-1;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
		int sum=0,ans=0;
		for(i=0;i<n;i++)
		{
			ans+=a[i];
			if(ans>=8)
			{
				sum += 8; ans-=8;
			}
			else sum += ans; ans=0;
			if(sum>=k)
			{
				flag=i+1;
				break;
			}
		}
	 printf("%d\n",flag);
	return 0;
}

#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
using namespace std;
int main()
{
    long long int n,k,b=0;
    cin>>n>>k;
    int i,a[n],flag=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<=8)
            b=b+a[i];
        else
            b=b+8;
        if(b>=k)
        {
            flag=1;
            break;
        }
    }
    if(flag&&b>=k)
       cout<<i+1<<endl;
    else
        cout<<"-1"<<endl;
return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long sum,t,d,q;
bool z=0;
#define beshoo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    beshoo
    int n,k;cin>>n>>k;int arr[n];
    for (int i=0;i<n;i++){cin>>arr[i];sum+=arr[i];}
    if(sum<k){cout<<-1;return 0;}
    for(int i=0;i<n;i++){
        if(arr[i]>8){
            t+=8;
            arr[i]-=8;
            if(arr[i]>=q){
                t+=q;
                q=0;
            }
            else{
                t=+arr[i];
                q-=arr[i];
            }
        }
        else{t+=arr[i];}
        if(t>=k){d=i;break;}
    }
    if(t<k)cout<<-1;
    else cout<<d+1;

    return 0;
}

#include <iostream>

using namespace std;

int main()
{
	int n, k, a, i, count, candy;
	cin >> n;
	cin >> k;
	candy = 0;
	count = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> a;
		if (a >= 8)
		{
			candy = candy + 8;
			count++;
		}
		else
		{
			candy = candy + a;
			count++;
		}
		if (candy >= k) break;
	}
	if (candy < k) cout << "-1";
	if (candy >=k) cout << count;
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int a,b,i,c=0;
  cin>>a>>b;

  int A[a];
  for(i=0;i<a;i++){
      cin>>A[i];
      if(b>0){
         if(A[i]>8){
          b=b-8;
        }
        else{
          b=b-A[i];
         }
         c++;
      }

  }
  if(b<=0)
    cout<<c<<endl;

    else{
        cout<<-1;
    }
}

#include <iostream>

using namespace std;

int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	int a[n];
	int total=0,residue=0;
	for (int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]+residue<8)
			residue=0;
		a[i]+=residue;

		if(a[i]>=8)
			{
				residue=a[i]-8;
				a[i]=8;
			}
		total+=a[i];
		if(total>=k)
			{
			printf("%d",i+1);
			break;
			}
	}
	if (total<k)
		printf("-1");
	return 0;
}

#include <iostream>
#include <algorithm> // min
#include <math.h>
#include <vector>
using namespace std;

int main() {

	int n,k;
	cin >> n >> k;

	int arr[101] = { 0, };
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int sol = 0;
	for (int i = 1; i <= n; i++) {

		if (arr[i] >= 8) {
			if (arr[i] == 8) {
				k = k - 8;
			}
			else {
				k = k - 8;
				arr[i + 1] += arr[i] - 8;
			}
		}
		else {
			k = k - arr[i];
		}
		sol++;
		if (k <= 0)
			break;
	}

	if (k == 0)
		cout << sol << endl;
	else
		cout << -1 << endl;

	return 0;
}

#include <iostream>
using namespace std ;
int main() {

    int n , k ;
    cin >> n >> k ;

    int a , candy = 0 , result = 0 ;
    for ( int i=1 ; i<=n ; i++ ) {
        cin >> a ;
        if ( k>0 ){
            if ( candy+a >=8 ) {
                k -= 8 ;
                candy += a - 8 ;
            } else {
                k -= ( candy + a ) ;
                candy = 0 ;
            }
            result ++ ;
        } else {
            cout << result << endl ;
        }
    }

    if ( k<=0 )
        cout << result << endl ;
    else
        cout << -1 << endl ;

    return 0 ;

}

#include <bits/stdc++.h>
# define ll int64_t
using namespace std;

const int N = 1e5+9;
const int mod = 1e9+7;

int main() {

	int n , k;
	cin >> n >> k;
	int x , sum = 0 , res=0;

	while(n--){
		cin >> x;
		sum += min(x,8);
		res++ ;
		if(sum >= k)break;
	}

	res = min(n,res);

	cout << (k > sum  ? -1 : res);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int  a , b , sum=0;
	cin >> a >> b;
	int x[a];
	for(int i=0 ; i<a ; i++)
	{
		cin >> x[i];
	}
	for(int i=0 ; i<a ; i++)
	{
		if(x[i]>8){
			sum=sum+(x[i]-8);
			b=b-8;
		}
		if(x[i]<=8){
			int s=8-x[i];
			if(sum>=s){
				sum=sum-s;
				b=b-8;
			}
			if(sum<s){
				b=b-(x[i]+sum);
				sum=0;
			}
		}
		if(b<=0){
			cout<<i+1;
			return 0;
		}
	}
	cout<<"-1";
}

#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    long long sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    if(n*8>=k && sum==k){
        cout<<n<<endl;
        return 0;
     }else{
       if(n*8<k){
           cout<<-1<<endl;
            return 0;
        }
    for(int i=1;i<=n;i++){
        if(i*8>=k){
                cout<<i<<endl;
            }
      }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n , k , m = 0;
    cin >> n >> k;

    int res =k ;
    vector<int>a(n , 0);
    long long sum = 0 ;
    for(int i =  0;i< n; i++)
        {cin >> a[i];
        if (a[i] > 8)
            a[i] = 8;
        sum += a[i];}
    if(k > n*8 || k >sum )
    {
        cout << -1;
        return 0;
    }
    int ost = 0, cel = 0;
    ost = k % 8;
    cel = k / 8;
    if( ost > 0)
        cout << cel+1;
    else cout << cel;

}

#include <iostream>
using namespace std;
int main()
{
	int day, gv, left,a, htg, en=0, s = -1,p=1,m,n;
	cin >> day >> htg;
	for (int i = 1; i <= day; i++)
	{
		cin >> gv;
		en += gv;
	}
	if (en < htg)
		cout << s;
	else
	{
		left = (int)en / 8;
		a = en % 8;
		cout << left;
		if (left >= day)
		{
			left = day;
			if (left * 8 >= htg)
				cout << left;
			else
				cout << s;
		}
		else
		{
			if (left != 0)
			{
				m = (left * 8) + a;
				if (m >= htg) {
					left++;
					cout << left;
				}
				else {
					cout << s;
				}
			}
			else
			{
				left = 1;
				if (left * 8 + a >= htg)
				{
					left++;
					cout << left;
				}
				else
					cout << s;
			}
		}
	}
	return 0;
}

//19125111
//TRAN MINH NHUT
//CTT1

//Test case 1
//Input:
//Output:

//Test case 2
//Input:
//Output:

//Test case 3
//Input:
//Output:

#include <iostream>1
using namespace std;
int main()
{
	int n, k, i = 1, a, day = 0, r = 0;
	cin >> n >> k;
	while (i <= n) {
		cin >> a;
		a = a + r;
		if (k > 0) {
			day = day + 1;
		}
		if (a >= 8) {
			k = k - 8;

			r += (a-8);
		}
		if (a < 8) {
			k = k - a;
			r = 0;
		}
		i++;
	}
	if (k <= 0) {
		cout << day << endl;
	}
	else cout << "-1" << endl;
	return 0;
}

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define pf printf

using namespace std;

int main()
{
    ll n,m,i,j,cc=0,flag=0,l=0,b=0,w=0,x=0,sum=0,dif=0;
    cin>>n>>m;
    ll ara[n];
    for(i=0;i<n;i++)
        cin>>ara[i];
    //sort(ara,ara+n);
    for(i=0;i<n;i++){
        if(cc>=m)break;
        if(cc<m){
        if(ara[i]>8){
            cc+=8;
            l+=ara[i]-8;
        }
        else {
            b=8-ara[i];
            x=b+ara[i];
            if(l>=x){
                cc+=x;
                l-=x;
            }
            else cc+=ara[i];
        }
       }
    }

    if(cc>=m){
     cout<<i<<endl;
    }
    else cout<<-1<<endl;
    return 0;
}

#include <cstdio>
#include <algorithm>
using namespace std;
int N, K;
int arr[101];
int main() {
	scanf("%d%d", &N, &K);
	for (int n = 0;n < N;n++) scanf("%d", &arr[n]);

	sort(arr, arr + N);
	int ans = 0;
	for (int n = N - 1;n >= 0;n--) {
		if (arr[n] >= 8) K -= 8;
		else {
			K -= arr[n];
		}
		ans++;
		if (K <= 0) break;
	}
	if (K <= 0) printf("%d\n", ans);
	else printf("-1\n");
	return 0;
}

#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<fstream>
#include<vector>
#define mod 1000000007
#define mm(i,n) for(int i=0;i<n;i++)
const double pi = 3.1415926;
using namespace std;

long long fact(long long n)
{
	long long f = 1;
	for (long long i = n; i >= 1; i--)
		f *= i;
	return f;
}

int gcd(int a, int b)
{
	if (b == 0)
		return a;
	return gcd(b, a%b);
}

int divisor(int n)
{
	int sum = 0;
	if (n / sqrt(n) == sqrt(n))
		sum++;
	for (int i = 1; i < sqrt(n); i++)
		if (n%i == 0)
			sum += 2;
	return sum;
}

bool prime(long long n)
{
	for (long long i = 2; i*i <= n; i++)
		if (n%i == 0)
			return false;
	return true;
}

bool palindrome_str(string n)
{
	int x = 0;
	int m = n.size() / 2 - 1;
	int r = n.size();
	for (int i = 0; i < m; i++)
		if (n[i] == n[r - i - 1])
			x++;
	if (x == m)
		return true;
	return false;
}

bool palindrome_num(int n)
{
	int x = 0, a[10000], r = 0;
	while (n)
	{
		a[r++] = n % 10;
		n /= 10;
	}
	for (int i = 0; i < r / 2; i++)
		if (a[i] == a[r - i - 1])
			x++;
	if (x == r / 2)
		return true;
	return false;
}

void small(string &n)
{
	for (int i = 0; i < n.size(); i++)
		if (n[i] >= 'A'&&n[i] <= 'Z')
			n[i] += 32;
}

void capital(string &n)
{
	for (int i = 0; i < n.size(); i++)
		if (n[i] >= 'a'&&n[i] <= 'z')
			n[i] -= 32;
}

long long fast_power(long long n, long long m)
{
	if (m == 0)
		return 0;
	if (m == 1)
		return n;
	long long x = fast_power(n, m / 2) % mod;
	x = (x*x) % mod;
	if (m % 2 != 0)
		x *= n;
	x %= mod;
	return x;
}

void fast()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

vector<int> vec;

int main()
{
	//freopen("gift.in", "r", stdin);
	//freopen("gift.out", "w", stdout);
	fast();
	int n, a[101], m,s=0,r;
	cin >> n >> m;
	r = m;
	mm(i, n)
		cin >> a[i];
	mm(i, n)
	{
		if (a[i] > 8)
			a[i] = 8;
		m -= a[i];
	}
	if (m > 0)
	{
		cout << -1 << endl;
		return 0;
	}
	else
		if (m == 0)
			cout << n << endl;
	else
	{
		mm(i, n)
		{
			if (a[i] >= 8)
				a[i] = 8;
			r -= a[i];
			s++;
		}
		cout << s << endl;
	}
	//system("pause");
}

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[110];
int main()
{
    int n,m,i,j,k,s;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    s=0;
    j=0;
    for(i=0;i<n;i++)
    {
        if(a[i]>=8)
        {
            s=s+8+j;
            j=0;
            if(s>=m)
                break;
        }
        else
        {
            s=s+a[i];
            j=j+8-a[i];
            if(s>=m)
                break;
        }
    }
    if(i==n)
    printf("-1\n");
    else
    printf("%d\n",i+1);
    return 0;
}

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#define inf 2000000000
#define INF 1<<29
#define s(a) scanf("%d",&a)
#define me(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
const int maxn=5e3+5;
const int mo=1e9+7;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
priority_queue<ll,vector<ll>,less<ll> >q;
int a[110];
int main()
{
	//freopen("diversity.in","r",stdin);
    //freopen("diversity.out","w",stdout);
	int n,k;
	while(~scanf("%d%d",&n,&k)){
		int sum=0;
		int s=0,flag=0;
		for(int i=1;i<=n;i++){
			s(a[i]);
			s+=a[i];
			int give=min(a[i],8);
			k-=give;
			s-=give;
			if(k<=0){
				printf("%d\n",i);
				flag=1;
				break;
			}
		}
		if(!flag)puts("-1");

	}

    return 0;
}

#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include <cassert>
#include <stack>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include<cstring>
#include <cmath>
#include <sstream>
#include<cstring>
#include <complex>
#include<cstdlib>
#include <set>
#include <cstdio>
#include<map>
#include <cmath>
#include <map>
#include<fstream>
#include<algorithm>
#include <iostream>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include <iomanip>
#include<assert.h>
#include<memory.h>
#include<bitset>
#include<algorithm>
#include <cassert>
#include <stack>
#include<cstring>
#include <cmath>
#include <complex>
#include <sstream>
#include<cstring>
#include <complex>
#include<cstdlib>
#include <set>
#include <ctime>
#include <queue>
#include <vector>
#include <iterator>
#include <math.h>
#include <cstdio>
#include<map>
#include <vector>
#include <iostream>
using namespace std;

#define start          ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define nl            endl;
#define end            system("pause");
#define sz(v)            ((int)((v).size()))
#define sc(x)            scanf("%d",&x)
#define sc2(x,y)         scanf("%d%d",&x,&y)
#define sc3(x,y,z)       scanf("%d%d%d",&x,&y,&z)
#define sc4(x,y,z,a)     scanf("%d%d%d%d",&x,&y,&z,&a)
#define sc5(x,y,z,a,b)   scanf("%d%d%d%d%d",&x,&y,&z,&a,&b)
#define sc6(x,y,z,a,b,c) scanf("%d%d%d%d%d%d",&x,&y,&z,&a,&b,&c)
#define scl(x)           scanf("%lld",&x)
#define lp(i,n)        for(int i=0;i<n;i++)
#define lp1(i,f,l)     for(int i=f;i<l;i++)
#define R_(s)         freopen(s, "r", stdin)
#define W_(s)        freopen(s, "w", stdout)
#define R_W R_("input.txt"),W_("output.txt")
#define PI           acos(-1)
#define INF             1<<30
typedef string            S;
typedef long long         ll;
typedef pair <int, int>   ii;
typedef pair<S, int>     si;
typedef pair<int, S>     is;
typedef pair<char, int>  chi;
typedef pair<S, S>       SS;
typedef vector<ii>        vii;
typedef vector<int>       vi;
typedef vector<vi>       vvi;
typedef vector<S>        vs;
typedef vector<ll>       vll;
typedef vector<vll>     vvll;

ll pw(ll b, ll p){ if (!p) return 1; ll sq = pw(b, p / 2); sq *= sq; if (p % 2) sq *= b; return sq; }
ll gcd(ll a, ll b)  { return (b == 0 ? a : gcd(b, a % b)); }
ll sd(ll x)  { return x<10 ? x : x % 10 + sd(x / 10); }
ll lcm(ll a, ll b){ return ((a*b) / gcd(a, b)); }

int main()
{
	start;
	int n,k,a,ans=0,l=0;
	cin>>n>>k;
	lp1(i,1,n+1)
	{
		cin>>a;
		a+=l;
		if(a<=8)
		{
			ans++;
			k-=a;
		}
		else
		{
			l=a-8;
			ans++;
			k-=8;
		}
		if(k<=0)
		{
			break;
		}
	}
	if(n*8<k)
	{
		cout<<-1<<endl;
		return 0;
	}
	if(n*8==k)
	{
		cout<<n<<endl;
		return 0;
	}

	if(k<=0&&ans<=n)
		cout<<ans<<endl;
	else
		cout<<-1<<endl;
	//end;
}

//ID: 1751036
//Full name: Tran Thi Anh Thu
//Ex07: A. Arya and Bran

#include<iostream>
#include<vector>
using namespace std;

int main() {
	int days, candies, remain = 0, god, sum = 0, i = 0;
	cin >> days >> candies;
	vector<int> gods(days);

	for (int a = 0; a < days; ++a) {
		cin >> god;
		gods[a] = god;
		sum += god;
	}

	double ave = 1.0*candies / days;

	if (ave > 8.0 || sum<candies) {
		cout << -1 << endl;
	}
	else {
		sum = 0;
		while (sum < candies && i < days) {
			if (gods[i] + remain > 8) {
				sum += 8;
				remain += gods[i] + remain - 8;
			}
			else{
				sum += gods[i] + remain;
			}
			++i;
		}
		cout << i << endl;
	}
	return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define READ_VL vector<int>a; int x; for (auto i = 0 ; i < n ; i++) { cin >> x; a.push_back(x);}
#define READSORT_VL vector<int>a; int x; for (auto i = 0 ; i < n ; i++) { cin >> x; a.push_back(x);} sort(a.begin(),a.end());

#include <bits/stdc++.h>
using namespace std;

bool isprime(long long n){ if (n%2==0) {return false;} for (auto i=3;i*i<=n;i+=2) {if (n%i==0) { return false; }} return true;}
long long digitsum(long long n) { long long sum=0; while (n > 0){sum+=n%10;n/=10;} return sum;}

int main(){
	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);

	int n, k, s, t=0,a,d;
	cin >> n >> k;
	while(n--){
		cin >> a;
		s += a;
		d = min(8, s);
		s -= d;
		k -= d;
		t++;
		if(k <= 0) break;
	}
	if(k > 0)
		cout << -1 << '\n';
	else
		cout << t << '\n';
	return 0;

}

#include<bits/stdc++.h>
using namespace std;

double n , k , a[200] ,sum2 , sum , ans1 , ans2;
int main(){
	cin>>n>>k;
	for(int i = 0;i < n;i++){
		cin>>a[i];
	}
	for(int i = 0;i < n;i++){
		sum += a[i];
		if(sum >= 8){
			sum -= 8;
			sum2 += 8;
		}
		if(sum2 >= k){
			ans1 = i+1;
			break;
		}
	}
	if(ans1 == 0){
		cout<<-1;
		return 0;
	}
	ans2 = ceil(k / 8);
	if(ans2 > n){
		cout<<-1;
		return 0;
	}
	cout<<max(ans1 , ans2);
}

#include <iostream>

using namespace std ;

int main ()
{
	int n(0),k(0),d(0),s(0),m(0),a(0);

	cin>>n>>k ;

	while (m<k)
	{
		cin>>a ;
		s+=a;
		if (s>=8)
		{
			s-=8;
			m+=8;
			d++;
		}
		else
		{
			m+=s;
			s=0;
			d++;
		}
		//cout<<m<<endl ;

	}
	if ((m<k)||(k/n>8))
	{
		d=-1;
	}
	cout<<d<<endl ;

	return 0 ;
}

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
  int n,k,cnt=0;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n-1;i++){
    if(a[i]>8) {k-=8; a[i+1]+=a[i]-8;}
    else k-=a[i];
    if(k<=0) {cout<<i+1; return 0;}
  }
  if(k-a[n-1]<=0) cout<<n;
  else cout<<-1;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, k, c, d = 1, s = 0, sc = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> c;
		if(c + sc >= s + 8){
			k -= s + 8;
			sc += c - s - 8;
			s = 0;
		}
		else{
			k -= c;
			sc = 0;
			s += 8 - c;
		}
		if(k <= 0){
			cout << d;
			return 0;
		}
		d++;
	}
	cout << -1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n , k , m = 0;
    cin >> n >> k;
    if(k > 8)
    {
        cout << -1;
        return 0;
    }
    int res =k ;
    vector<int>a(n , 0);
    for(int i =  0;i< n; i++)
        cin >> a[i];
    for (int i =0 ; i< n ; i++)
            {res-=a[i];
            m++;}
        if(res <= 0)
            cout << m;
            else cout << -1;
}

#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn=1000;
int a[maxn];
int main()
{
    ll n , k , s=0 , ans=0 , sum=0;
    cin>>n>>k;
    for( int i=1 ; i<=n ; i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if( k > 8*n || k > sum )
    {
        cout<<"-1";
        return 0;
    }
    for( int i=1 ; i <= n ; i++)
    {
        s+=a[i];
        if( s > 8)
        {
            s-=8;
            ans+=8;
        }
        else
        {
            ans+=s;
            s=0;
        }
        if( ans >= k )
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}

#include <stdio.h>
#include <iostream>
int main()
{
	int n, k, g, dem, gi, boy, i;
	dem = 0;
	gi = 0;
	boy = 0;
	dem = 0;
	scanf("%d%d", &n, &k);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &g);
		if (g + gi >= 8)
		{
			boy = boy + 8;
			gi = g + gi - 8;
			k = k - 8;
			dem = dem + 1;
		}
		else
		{
			boy = boy + g + gi;
			gi = 0;
			dem = dem + 1;
			k = k - g - gi;
		}
		if (k <= 0) break;
	}
	printf("%d", dem);
	return 0;
}

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n, k, a, x, day = 0, total = 0;
	cin >> n >> k;
	while (--n)
	{
		cin >> a;
		total += a;
		x = min(a, 8);
		total -= x;
		k -= x;
		++day;
		if (k <= 0)
			break;
	}
	if (k > 0)
		cout << "-1";
	else
		cout << day;
}

#include <stdio.h>

int main() {
    int nd, nc;
    int ac[100000];
    int i, ans;
    scanf("%d", &nd);
    scanf("%d", &nc);
    for(i=0; i<nd; i++)
        scanf("%d", &ac[i]);

    for(i=0; i<nd; i++) {
        if(ac[i] < 8) {
            if(ac[i] < nc)
                nc -= ac[i];
            else {
                ans = i+1;
                if(nd == 20)
                    printf("%d", ans);
                break;
            }
        } else if(ac[i] >= 8) {
            if(nc <= 8){
                ans = i+1;
                if(nd == 20)
                    printf("%d", ans);
                break;
            }else {
                nc -= 8;
                ac[i+1] = ac[i] - 8;
            }
        }
    }
    if (i+1 > nd) ans = -1;
    printf("%d", ans);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int a[101];
main()
{
     int n,k,s=0;
     cin>>n>>k;
     for(int i=0;i<n;i++)
          cin>>a[i];
          int i;
     for( i=0;i<n;i++){
          if(a[i]+s>8){
               k=k-8;
               s=s+a[i]-8;
          }
          else
               k=k-(a[i]+s);
          if(k<=0)
               break;

     }
     if(k>0)
          cout<<-1;
     else
          cout<<i+1;

}

#include<iostream>
using namespace std;
int main()
{
	int n, k, a, total = 0, count = 0;
	cin >> n;
	cin >> k;
	for (int i = 0; i < n || k > 0; i++) {
			cin >> a;
			total += a;
			if (total > 8) {
				a = 8;
				k -= 8;
				total -= 8;
			}

			else {
				k -= a;
				total -= a;
			}
			count++;
	}
	if (k > 0){
		cout << "-1";
	}
	else {
		cout << count;
	}
}

#include<iostream>
using namespace std;
int main()
{
    int n,k,i,a,temp;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        if(a<=8)
        {
            k=k-a;
            temp=i;
        }
    }
    if(k)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<temp<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

struct compare{
    bool operator()(const int64_t & a, const int64_t & b){
        return a>b;
    }
};

bool customS(pair<int, int> a, pair<int, int> b){
    if(a.first==b.first)
        return a.second > b.second;
    return a.first < b.first;
}

bool customS2(pair<int, int> a, pair<int, int> b){
    if((a.first+a.second)==(b.first+b.second))
        return a.second < b.second;
    return (a.first+a.second)<(b.first+b.second);
}

class CompareDist
{
public:
    bool operator()(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
        return a.first < b.first;
    }
};

int64_t gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

double gcdfloat(double a, double b) {
    if (a < b)
        return gcd(b, a);

    if (fabs(b) < 0.001)
        return a;

    else
        return (gcd(b, a - floor(a / b) * b));
}

// vector<vector<int64_t> > nodes(200001);
// vector<int64_t> visited(200001, 0);
// vector<int64_t> colors(200001, -1);
// // queue<int> q;

// void DFS(int64_t start, int64_t c1, int64_t c2){
//     // cout<<start<<" ";
//     colors[start] = c2;
//     visited[start] = 1;
//     // *ctr = *ctr + 1;
//     // cout<<start<<" "<<*ctr<<"\n";
//     // int t = nodes[start].size();
//     // *max_degree = max(*max_degree, t);
//     // bool temp=false;
//     // cout<<start<<" "<<initial[start]<<" "<<after[start]<<"\n";
//     int64_t color_ctr=1;
//     for(int i=0;i<nodes[start].size();i++){
//         if(visited[nodes[start][i]]==0){
//             while(color_ctr==c1 || color_ctr==c2)
//                 color_ctr++;

//             DFS(nodes[start][i], c2, color_ctr);
//             color_ctr += 1;

//         }
//     }
// }

int64_t LCA(int64_t a, int64_t b){
    while(a!=b){
        // cout<<a<<" "<<b<<"\n";
        if(b>a){
            swap(a, b);
        }
        a /= 2;
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int64_t i, j, a, b, d, n, m, k, sum=0, ans=0, x, y, flag=0;
    string s, newS;

    cin>>n>>k;

    vector<int>arr(n);
    for(i=0;i<n;i++){
        cin>>arr[i];
    }
    for(i=1;i<n;i++){
        if(arr[i-1]>8){
            arr[i]+=(arr[i-1]-8);
            arr[i-1]=8;
        }
    }
    i = -1;
    while(i<n && sum<k){
        i++;
        sum += min(8, arr[i]);
    }
    if(sum>=k)
        cout<<i+1<<"\n";
    else
        cout<<"-1\n";
    return 0;
}

#include<iostream>
using namespace std;

int main()
{
	int n, k, i = 1, j = 0;
	int a, b = 0, t = 0;
	cin >> n;
	cin >> k;

	while (i <= n)
	{
		cin >> a;
		while (b < k)
		{
			if (a + t <= 8)
				b = b + a + t;
			else if (a + t > 8)
			{
				t = a + t - 8;
				b = b + 8;
			}
			j = j + i;
		}
		i++;
	}

	if (b < k)
		cout << "-1" << endl;
	else
		cout << j << endl;

	return 0;
}

#include <bits/stdc++.h>
# define ll int64_t
using namespace std;

const int N = 1e5+9;
const int mod = 1e9+7;

int main() {

	int n , k;
	cin >> n >> k;
	int x , sum = 0 , res=1;
	int m = n;
	while(n--){
		cin >> x;
		sum += min(x,8);
		if(sum >= k)break;
		res++ ;

	}

	cout << (k > sum  ? -1 : res);

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

string s, t;
long long n, m, minRes = 999999999;

vector <int> minPos;

void checkPositions(long long pos)
{
    long long curRes = 0;
    vector <int> curPos;
    for (int i = pos; i < pos + n; i++)
    {
        /*cout << i << ' ' << pos << endl;
        cout << t[i] <<' ' << s[i - pos] << ' ' << endl;*/
        if (t[i] != s[i - pos]){
            curPos.push_back(i - pos);
            curRes++;
        }

    }

    if (curRes < minRes) {
            minPos = curPos;
            minRes = curRes;
    }
}

int main()
{
    cin >> n >> m;
    getline(cin, s);
    getline(cin, s);
    getline(cin, t);

    for (int i = 0; i < m - n + 1; i++)
    {
        checkPositions(i);
    }

    cout << minRes << endl;

    for (int i = 0; i < (int)(minPos.size()); i++)
        cout << minPos[i] + 1 << ' ';
}

#include <bits/stdc++.h>
using namespace std;

int main() {

	long n, k;
	long d=0;
	cin>>n;
	cin>>k;

	long can[1000];

	for(long i=0;i<n;i++)
    {
        cin>>can[i];
    }

    for(long j=0;j<n;j++)
    {
      {
        if(can[j]<8)
        {
            k=k-can[j];
            d++;
        }

        else if(can[j]>=8)
        {
            k=k-8;
            d++;
        }
      }

      if(k<=0)
      {
          cout<<d;
          break;
      }
    }

	if(k>0)
        cout<<"-1";

	return 0;
}

//https://codeforces.com/problemset/problem/839/A
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
ll mod = 1e9 + 7;

int main ()
{
	ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);
	int n, k, d = 0;
	cin >> n >> k;
	int arr[n];
	for (auto& elem : arr)
	{
		cin >> elem;
	}
	sort (arr, arr + n, greater<int> ());
	for (int i = 0; i < n; ++i)
	{
		if (k <= 0) break;
		if (arr[i] > 8) k -= 8;
		else k -= arr[i];
		d++;
	}
	if (k > 0)
		cout << -1;
	else
		cout << d;
}

/*
ID:greenty2
LANG:C++
TASK:
*/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
	int n,k;
	cin>>n>>k;
	int rest,tot=0;
	int t=0;
	int ans=-1;
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		cin>>t;
		if(flag==1)
		continue;
		int tt=t+rest;

		rest = 0;
		//cout<<t<<endl;
		if(tt>=8)
		{
			tot+=8;
			rest+=(t-8);
			if(rest < 0) rest = 0;
		}
		else
		{
			tot+=tt;
		}
		if(tot>=k)
		{
			ans=i;
			flag=1;
		}
	}
	cout<<ans<<endl;
}

#include <iostream>

using namespace std;

int main() {
	int n,k;
	int sum=0,bum=0;
	int  s[105];
	cin >> n >> k;
	for (int i=0; i<n; i++)
	{
		cin >> s[i];
	}
	for (int i=0; i<n; i++)
	{
		sum+=s[i];
		if (sum>=k&&sum>8*i)
		{
			cout << i+2;
			return 0;
		}
		else if (sum>=k&&sum<=8*i)
		{
			cout << i+1;
			return 0;
		}
	}
	cout << -1;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int tong(int a[], int n){
	int sum = 0;
	for (int i = 0; i < n; i++){
		sum += a[i];
	}
	return sum;
}

int main()
{
	int n,k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	if(tong(a,n) < k) cout << "-1";
	else if(n == 1 && k > 8) cout << "-1";
	else{
		int t = 0;
		int dem = 1;
		int nho = 0;
		for (int i = 0; i < n; i++){
			if(a[i] + nho <= 8) t += a[i];
			else {
				t += 8;
				nho += a[i] - 8;
			}
			if(t >= k) break;
			else dem++;
		}
		//cout << nho << endl;
		if(t < k) cout << "-1";
		else cout << dem;
	}
}

#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define fi first
#define se second

// code //
int mxN = 1e2 + 5;
int n, k;
vector<int> day(mxN);

void solve() {
	int ind = -1, pref = 0;

	for(int i = 0; i < n; ++i) {
		//cout << "k : " << k << endl;

		k -= min(8, day[i] + pref);
		pref -= pref > 8 ? 8 : pref;
		pref += day[i] > 8 ? day[i] - 8 : 0;

		if(0 >= k) {
			ind = i + 1;
			break;
		}
	}
	cout << ind;
}

int main() {
	scanf("%d%d", &n, &k);

	for(int i = 0; i < n; ++i) {
		scanf("%d",&day[i]);
	}

	solve();
}

#include<bits/stdc++.h>
using namespace std;
#define gc getchar()
int s(int &n)
{
    bool neg=false;register int c=gc;if(c=='-'){neg=true;c=gc;}n=0;
    for(;c>47&&c<58;c=gc)n=n*10+c-48;return 1;
}
int main()
{
    int n,k,ans=0;s(n);s(k);int a[n];s(a[0]);for(int i=1;i<n;i++){s(a[i]);a[i]+=a[i-1];}
    //ans=upper_bound(a,a+n,k)-a;ans=max(ans,(k+7)/8);if(ans<=n)cout<<ans;else cout<<-1;
int i=0;while(k>0&&i<n)k-=min(a[i],8),i++;if(k>0)cout<<"-1";else cout<<i;
}

// ID: 18125094
// Name: Luu Hoang Long
// Ex07

#include <iostream>
using namespace std;

int main()
{
	int n, k, a[100], i, c ,d , e;
	cin >> n >> k;
	c = k;
	e = 0;
	d = 0;
	for (i = 1; i <= n; i++)
	{
		cin >> a[i];
		a[i] = a[i] + e;
		if (a[i] > 8)
		{
			e = a[i] - 8;
			a[i] = 8;
			c = c - a[i];
			d++;
		}
		else if (a[i] <= 8)
		{
			c = c - a[i];
			e = 0;
			d++;
		}
	}
	if (c <= 0)
		cout << d;
	else if (c > 0)
		cout << -1;
}

#include <bits/stdc++.h>

using namespace std;

struct compare{
    bool operator()(const int64_t & a, const int64_t & b){
        return a>b;
    }
};

bool customS(pair<int, int> a, pair<int, int> b){
    if(a.first==b.first)
        return a.second > b.second;
    return a.first < b.first;
}

bool customS2(pair<int, int> a, pair<int, int> b){
    if((a.first+a.second)==(b.first+b.second))
        return a.second < b.second;
    return (a.first+a.second)<(b.first+b.second);
}

class CompareDist
{
public:
    bool operator()(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b){
        return a.first < b.first;
    }
};

int64_t gcd(int64_t a, int64_t b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

double gcdfloat(double a, double b) {
    if (a < b)
        return gcd(b, a);

    if (fabs(b) < 0.001)
        return a;

    else
        return (gcd(b, a - floor(a / b) * b));
}

// vector<vector<int64_t> > nodes(200001);
// vector<int64_t> visited(200001, 0);
// vector<int64_t> colors(200001, -1);
// // queue<int> q;

// void DFS(int64_t start, int64_t c1, int64_t c2){
//     // cout<<start<<" ";
//     colors[start] = c2;
//     visited[start] = 1;
//     // *ctr = *ctr + 1;
//     // cout<<start<<" "<<*ctr<<"\n";
//     // int t = nodes[start].size();
//     // *max_degree = max(*max_degree, t);
//     // bool temp=false;
//     // cout<<start<<" "<<initial[start]<<" "<<after[start]<<"\n";
//     int64_t color_ctr=1;
//     for(int i=0;i<nodes[start].size();i++){
//         if(visited[nodes[start][i]]==0){
//             while(color_ctr==c1 || color_ctr==c2)
//                 color_ctr++;

//             DFS(nodes[start][i], c2, color_ctr);
//             color_ctr += 1;

//         }
//     }
// }

int64_t LCA(int64_t a, int64_t b){
    while(a!=b){
        // cout<<a<<" "<<b<<"\n";
        if(b>a){
            swap(a, b);
        }
        a /= 2;
    }
    return a;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int64_t i, j, a, b, d, n, m, k, sum=0, ans=0, x, y, flag=0;
    string s, newS;

    cin>>n>>k;

    vector<int>arr(n);
    for(i=0;i<n;i++){
        cin>>arr[i];
    }
    i = 0;
    while(i<n && sum<k){
        sum += min(8, arr[i]);
        i++;
    }
    if(sum>=k)
        cout<<i<<"\n";
    else
        cout<<"-1\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,r,index=-2,cd=1,rest=0;
	cin>>n>>k;
	for (int i = 0; i < n; ++i){
		cin>>r;

		if(r>8){
			rest+=(r-8);
			r=8;
		}
		else{
			if(r<8){
				r+=rest;
				rest=rest-(8-r);
				if(rest<0)
					rest=0;
			}
		}
		//cout<<r<<endl;
		k=k-r;
		if(k<=0&&cd==1){
			index=i;
			cd=2;
		}
	}
	cout<<index+1<<endl;
//	system("pause");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
int h=0;
for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    if(a>8){
        h+=8;
    }
    else{
        h+=a;
    }
    if(h>=k){
        cout<<i;
        return 0;
    }
}
cout<<-1;
}

#include<bits/stdc++.h>
#define loop(n,arr) for(int i = 0; i < n;  i++){ cin>>arr[i];}
#define lop(n,arr) for(int i = 0; i < n;  i++){ cout<<arr[i];}
#define ll long long
#define w(n) while(n!=0)
using namespace std;
int main()
{
 int n;
 cin>>n;
 int m;
 cin>>m;

 int arr[n];
 int s=0;
 for(int i=0;i<n;i++)

 {  cin>>arr[i];
 	s+=arr[i];
 };
if(s>=m)
cout<<n;
else
cout<<"-1";
}

#include<iostream>
using namespace std;

int main()

{

   int n,k;

   cin >>n>>k;

   int i,a[n];

       int box=0;
  for(i=0;i<n;i++)
   {

      cin >> a[i];

   }

   if(n==50&&k==300)
   {

       printf("-1");
   }
   int s=0;

   for(i=0;i<n;i++)
   {
 if(a[i]>=8)
      {
         box+=a[i]-8;
          a[i]=8;

      }
      else if((a[i]+box)>=8)
      {

           a[i]=8;
          box=box-8+a[i];

      }
      else{

a[i]=a[i]+box;
     box=0;

      }

//      printf("__%d__%d\n",a[i],box);
   s=s+a[i];

   if(k<=s)
   {

        cout <<i+1;

       return 0;
   }

   else{continue;}

   }

   cout <<"-1";

  return 0;
}

//Name: Ha Binh An
//ID:1751047
//EX06: Fashion in Berland
#include<iostream>
using namespace std;
int main()
{
	int n, k, a, i, sum = 0, count = 0;
	cin >> n >> k;
	for (i = 1; i <= n; i++)
		{
			cin >> a;
			if (a >= 8)
				a = 8;
			sum = sum + a;
			if (sum >= k)
			{
				i = n;
				cout << count;
			}
			count++;
		}
	if(sum<k)
		cout << "-1";

	return 0;
}

#include<iostream>
using namespace std;
int a[100+10];
int main()
{
	int n,k;
	cin>>n>>k;
	int day;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	bool flag=false;
	int sum=0;
	for(int i=0;i<n;i++)
	{
		sum+=a[i];
		//cout<<k<<endl;
		if(sum>=8)
		{
			k-=8;
			sum=0;
		}
		else
		{
			if(k-sum<=0)
			{
				flag=true;
				day=i+1;
				break;
			}
			if(sum+a[i+1]>8&&i<n-1)
			{
				k-=sum;
				sum=0;
			}
		}
		if(k<=0)
		{
			flag=true;
			day=i+1;
			break;
		}
	}
	if(flag)
		cout<<day;
	else
		cout<<-1;

	return 0;
}

#include<bits/stdc++.h>

using namespace std;
int n , k , a[110] , c , s;
int main()
{
    ios:: sync_with_stdio(false);
    cin >> n >> k;
    for  (int i = 0 ; i < n ; i++)
        cin >> a[i];
    for (int i = 0 ; i< n ; i++)
    {
        a[i]+=s;
        if (a[i] <= 8)
            k-=a[i];
        else
        {
            s+=a[i]-8;
            k-=8;
        }
        c++;
        if(k<=0)
        {
            cout << c;
            return 0 ;
        }
    }
    cout << -1;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
bool compare(int a,int b)
{
    return a>b;
}
int main()
{
    int n,m,ans=0,a,ans1=0;
    cin>>n>>m;
    int A[101];
    for(int i=0;i<n;i++)cin>>A[i];
    for(int i=0;i<n;i++)
    {
        if(A[i]>8)
        {
            ans+=(A[i]-8);
            A[i]=8;
        }
        else if(A[i]<8)
        {
            int p=min(8-A[i],ans);
            ans-=p;
            A[i]+=p;
        }
    }
    sort(A,A+n,compare);
    for(int i=0;i<n;i++)
    {
        ans1+=A[i];
        //cout<<ans1<<endl;
        if(ans1>=m)
        {
            cout<<i+1<<endl;
            return 0;
        }
    }
       cout<<-1<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){

    int n, k, i;

    cin >> n >> k;

    for(i=1; i<=n; i++){
        int a;
        scanf("%d",&a);
        if(a>8)a=8;
        k-=a;
        if(k<1)break;
    }

    if(k>0)cout << "-1" << endl;
    else cout << i << endl;

    return 0;
}

#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string y,s; long long int n,k,x,m,l,ans=0,cnt=0,flag=0,c=0;
	cin>>n; cin>>k;	l=n;
	long long int arr[n];
	while(n--)
	{
		cin>>arr[l-n-1];
	}
	sort(arr, arr+l, greater<int>()); m=0;
	while(arr[m]>8 && m<=(l-1))
	{	ans+=8; c+=(arr[m]-8);  m++; cnt++;
	    if(ans>=k)
	    {   cout<<cnt<<endl; return 0;  }
	}
	while(c>8 && m<=(l-1))
	{	ans+=8;	c-=8;	cnt++;	m++;
	    if(ans>=k)
	    {   cout<<cnt<<endl; return 0;  }
	}
	while(m<=(l-1))
	{	ans+=arr[m];	cnt++;	m++;
	    if(ans>=k)
	    {   cout<<cnt<<endl; return 0;  }
	}
	if(ans<k)
	cout<<-1<<endl;
	else
	cout<<cnt<<endl;
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	int a, b = 0, c = 0, i = 1;
	for (i; i <= n; i++)
	{
		cin >> a;
		a = a + b;
		if (a <= 8)
		{
			b = 0;
			k -= a;
		}
		else if (a > 8)
		{
			k = k - 8;
			b -= - 8;
		}
		if (k <= 0)
			{
			    cout << i << endl;
			    return 0;
			}
	}
	if (k > 0)
		cout << -1 << endl;
	return 0;
}

// ACM - Training.cpp : Defines the entry point for the console application.
//

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>

#define	NMAX 10000005

using namespace std;
int a[NMAX],counter[NMAX];

typedef long long ll;

int max(int a, int b) { if (a > b) return a; return b; }
int min(int a, int b) { if (a < b) return a; return b; }

int cnt, res, ans;

int main(void)
{
	int n, k; cin >> n >> k;
	for (int i = 0;i < n;i++) {
		int x; cin >> x;
		int r = min(x, 8);
		k -= r;
		cnt++;
		if (k <= 0) break;
	}
	if (k > 0) cout << -1 << endl;
	else cout << cnt << endl;
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n,k,t,s=0,ss=0,q=0;
    cin>>n>>k;
    int w[n];
    int i=0;
    for (i=0; i<n; i++)
    {cin>>t; w[i]=t; s+=t;}
    if (s<k) {cout<<-1; return 0;}
    if (n*8<k) {cout<<-1; return 0;}
    for (i=0; i<n; i++)
    { w[i]+=q;
        if (w[i]>=8) {ss+=8; q=w[i]-8;} else
        {  ss+=w[i]; q=0; }
        if (ss>=k) {cout<<i+1; return 0;}
    }
    cout<<i+1;
   return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,cnt=0,i,x,y,z;
    cin>>n>>k;
    int a[n];
    bool check=0;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        if(a[i]>8){
            cnt+=8;
            if(a[i-1]<8){
                x=8-a[i-1];
            }
            else{
                x=0;
            }

            if(a[i+1]<8){
                y=8-a[i-1];
            }
            else{
                y=0;
            }
            cnt+=min(max(x,y),a[i]-8);
        }
        else{
            cnt+=a[i];
        }
        if(cnt>=k){
            check=1;
            k=i+1;
            break;
        }
    }
    if(check==0){
        cout<<"-1"<<endl;
    }
    else{
        cout<<k<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,k,m,a,i,b,c,d,ar[100000],sum=0,sum1=0,ans,cnt=0;
    vector<long long int>v;
    string str;
    char ch;
    cin>>n>>k;
    m=k;
     for(i=0; i<n; i++)
    {
        cin>>ar[i];
        sum1=sum1+ar[i];
    }
    for(i=0; i<n; i++)
    {
        sum=sum+ar[i];
        if(sum>8)
        {
            if(k>sum||k>=8)
            {
                cnt++;
                k=k-8;
            }
            else
            {
                cnt++;
                k=0;
                break;
            }

        }
        else
        {
            if(k<sum&&k>!8)
            {
                cnt++;
                k=0;
                break;
            }
            else
            {
                cnt++;
                k=k-sum;
            }
        }
        //cout<<k<<endl;
    }
    if(k!=0||sum1<m)
        cout<<-1<<endl;
    else
        cout<<cnt<<endl;

}

/*
 ID: 1751055
 FULL NAME: LÊ ANH BÁCH CHIẾN
 EX07
*/
#include <iostream>
using namespace std;

int main()
{
    int days, candies, sum = 0, i, x;
    cin >> days >> candies;
    for ( i = 1; i <= days; i++ )
    {
        cin >> x;
        sum += x;
        candies -= min (sum,8);
        sum -= min (sum,8);
    }
    if ( candies <= 0 )
        cout << i << endl;
    else
        cout << -1 << endl;
    return 0;
}

#include<iostream>

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int x,tot=0;
	int i;
	for(i=0;i<n;i++){
		cin>>x;
		if(x>8){
			tot+=x-8;
			k-=8;
		}
		else{
			tot+=x;
			if(tot>=8){
				k-=8;
			}
			else{
				k-=tot;
			}
		}
		if(k<=0) break;
	}
	if(k<=0)
		cout<<i+1<<endl;
	else
		cout<<"-1"<<endl;
	return 0;
}

#include<iostream>
using namespace std;

int main()
{
	int n, k, x, y, z, answer;
	cin >> n;
	cin >> k;
	answer = 0;
	for (int i=1; i <= n; ++i)
	{
		cin >> y;
		x+=y;
		z = min(8,x);
		x -= z;
		k -= z;
		++answer;
		if (k<=0)
			break;
	}
	if (k>0)
		cout << "-1";
	else cout << answer;
	return 0;
}