#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int ll;
typedef long double ld;

#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define rep(i,n)   for(int (i) = 0; (i) < (n); ++(i))
int MAX(int a, int b) {
	return (a>b)?a:b;
}
int main(int argc, char const *argv[]) {
	int n,k;
	scanf("%d%d",&n,&k);
	int *arr = (int*)calloc(n,sizeof(int));
	rep(i,n)scanf("%d",&arr[i]);
	int ans = 0, rem = 0;
	rep(i,n) {
		ans = i;
		if (arr[i]>8) {
			rem+=arr[i]-8;
			k-=8;
		} else {
			rem+=arr[i];
			if (rem>8) {
				rem-=8;
				k-=8;
			} else {
				k-=rem;
				rem=0;
			}
		}
		if (k<=0)
			break;
	}
	if (k>0)
		printf("-1\n");
	else
		printf("%d\n", ans+1);
	return 0;
}

#include <stdio.h>
int main()
{
    int n,k,a,i=0,j,x=0;
    scanf("%d%d",&n,&k);
    while(n--)
    {
        scanf("%d",&a);
        x=x+a;
        if(x<=8)
           {
            k=k-x;
            x=0;}
        else if(x>8)
            {
                k=k-8;
                x=x-8;
                }
            i++;
        if(k<=0)
        {
            printf("%d",i);
            return 0;
        }
        }
        printf("-1");
        return 0;
}

#include<stdio.h>

int main()
{
    int n,k,i,sum=0;
    scanf("%d %d",&n,&k);

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

      if(k>total)
        printf("-1");
       else if(k>(n*8))
        printf("-1\n");
       else
       {
           for(i=0;i<n;i++)
           {
               if(a[i]<8)
             {
                  sum=sum+a[i];
               if(sum>=k)
               {
                   printf("%d\n",i+1);
                   break;
               }

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

                 if(sum>=k)
                 {
                      printf("%d\n",i+1);
                      break;
                 }
                 if(i==(n-1) && sum<k)
                 {
                     printf("-1");
                     break;
                 }

             }
           }
       }

    return 0;
}

#include<stdio.h>

int main()

{
    int n,k,sum=0,days=0,i,count;

    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){
            sum=sum+8;
            if(sum<k)
                days++;
            if(sum>=k && days<=n){
                days++;
                printf("%d\n",days);
                break;
            }
            if(n==days){
                printf("-1");
                break;
            }

        count=a[i]-8;
        a[i+1]+=count;
        }

    if(a[i]<8){
        sum=sum+a[i];
        if(sum<k)
                days++;
            if(sum>=k && days<=n){
                days++;
                printf("%d\n",days);
                break;
            }
            if(n==days){
                printf("-1");
                break;
            }
    }
    }
return 0;
}

#include<stdio.h>
int main()
{
	int i,j,n,k,arr[100]={0},sum=0,val=0,ans=0;
	scanf("%d %d",&n, &k);
	for(i=0; i<n; i++)
	{
		scanf("%d",&arr[i]);
	}
	for(i=0; i<n; i++)
	{
		if(sum >= k)
		{
			ans = i;
			break;
		}
		arr[i] = arr[i] + val;
		if(arr[i] > 8)
		{
		val = arr[i] - 8;
		sum = sum + 8;
		}
		else
		{
			sum = sum +arr[i];
			val = 0;
		}
	//	printf("%d\n",sum);

	}
	if(sum >= k)
		{
			ans = i;
		}
	if(sum < k)
	{
		ans = -1;
	}
	printf("%d\n",ans);

}

#include<stdio.h>

int main()
{
	int n, k, i, a, s, b, c;
	scanf("%d %d",&n,&k);

	s = 0;
	b = 0;
	c = -1;

		for (i = 1;i<=n;i++)
		{
			scanf("%d", &a);

			s = s + a;
			if (s > 8)
			{
				b = b + 8;
				s = s - 8;
			}
			else
			{
				b = b + s;
				s = s - s;
			}

			if (b >= k)
			{
				c = i;
				break;
			}
		}

		printf("%d", c);
	return 0;
}

#include<stdio.h>
int a[100005];
int main()
{
    int n,k,i;
    int flag=0;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
    {
         if(a[i]>8)
        {
            k-=8;
            a[i+1]+=a[i]-8;
        }
        else k-=a[i];
        if(k<=0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        printf("%d\n",i);
    else printf("-1\n");

    return 0;

}

#include<stdio.h>

int main()
{
	int n, k, i, a, s, b, c;
	scanf("%d %d",&n,&k);

	s = 0;
	b = 0;
	c = -1;

		for (i = 1;i<=n;i++)
		{
			scanf("%d", &a);

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

			if (b >= k)
			{
				c = i;
				break;
			}
		}

		printf("%d", c);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <string.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
    int a[n];
	for(int i=0;i<n;i=i+1){
		scanf("%d",&a[i]);
	}
	if(k>n*8){
		printf("-1");
		return 0;
	}
	int count=0;
	for(int i=0;i<n-1;i=i+1){
		if(a[i]<=8&&k>0){
			k=k-a[i];
    		count+=1;
		}else if(a[i]>8&&k>0){
			k=k-8;
			a[i+1]+=a[i]-8;
    		count+=1;
		}
	}
	if(a[n-1]>8){
		a[n-1]=8;
	}
	if(k>0){
		k=k-a[n-1];
		count+=1;
	}
	if(k<=0){
		printf("%d",count);
		return 0;
	}
	printf("-1");
	return 0;
}

#include <stdio.h>
#define N 100

void give(int *caramelleArya, int k, int *caramelleBran)
{
    int d=k-*caramelleBran, caramelleDonabili; //caramelle mancanti a Bran

    if (*caramelleArya>8) caramelleDonabili=8;
    else caramelleDonabili=*caramelleArya;

    if (caramelleDonabili-d>=0){
        *caramelleBran+=d;
        return;
    }

    *caramelleBran+=caramelleDonabili;
    *caramelleArya-=caramelleDonabili;
}

int main() {

    int n, k, a[N], caramelleArya=0, caramelleBran=0, giorni=0;

    scanf("%d %d", &n, &k);

    for (int i=0; i<n && caramelleBran!=k; ++i){

        scanf("%d", &a[i]);

        caramelleArya+=a[i];

        give(&caramelleArya, k, &caramelleBran);

        ++giorni;
    }

    if (caramelleBran!=k) printf("%d", -1);
    else printf("%d", giorni);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <string.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
    int a[n];
	for(int i=0;i<n;i=i+1){
		scanf("%d",&a[i]);
	}
	int count=0;
	for(int i=0;i<n-1;i=i+1){
		if(a[i]<=8&&k>0){
			k=k-a[i];
			count+=1;
		}else if(a[i]>8&&k>0){
			k=k-8;
			a[i+1]+=a[i]-8;
			count+=1;
		}
	}
	if(a[n-1]>8){
		a[n-1]=8;
	}
	if(k>0){
		k=k-a[n-1];
		count+=1;
	}
	if(k<=0){
		printf("%d",count);
		return 0;
	}
	printf("-1");
	return 0;
}

#include <stdio.h>

int main()
{
	int n,k,s,g=0,t=0;
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&s);
		t+=s;
		if(t<=8) {k-=t;t=0;}
		else {t-=8; k-=8;}
		g++;
		if(k<=0) break;

	}
	if(k>0) printf("%d\n", -1);
	else printf("%d\n", g);
	return 0;
}

#include <stdio.h>
main ()
	 {
	 int ans=0,n,k,a[101],sum=0,i;
	 scanf("%d %d",&n,&k);
	 for (i=0;i<n;i++)
	 	 scanf("%d",&a[i]);
	 for (i=0;i<n;i++)
	 	 {
	 	  sum+=a[i];
	 	  if (sum>=8)
		  	 {ans+=8;sum=sum-8;}
	 	  else {ans+=sum;sum=0;}

		  if (k<=ans) {printf ("%d",i+1);return 0;}
		 }
	 printf("-1");
	 return 0;
	 }

#include<stdio.h>
#include<string.h>
int cmpfunc (const void * a, const void * b)
{
    return ( *(int*)a - *(int*)b );
}

main()
{
    int n, k, i, j;
    scanf("%d %d", &n, &k);
    int sum = 0, cnt = 0;
    int a[n];

    for(i = 0; i<n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
        if(sum>=8)
        {
            cnt +=  8;
            sum = sum - 8;
        }
        else
        {
            cnt += sum;
            sum = 0;
        }

        if(cnt>=k)
        {
            printf("%d", i+1);
            return 0;
        }
    }

    printf("-1");

}

#include <stdio.h>

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

    printf("-1\n");

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, k, candy, days=0, i, ans=0, temp=0, remain=0;
    scanf("%d%d", &n, &k);
    for(i=0; i<n; i++){
        scanf("%d", &candy);
        candy+=remain;
        if(candy<=8){
            ans+=candy;
            remain = 0;
        }
        else{
            remain = candy-8;
            ans+=8;
        }
        days++;
        if(ans>=k){
            temp=1;
            break;
        }
    }
    if(k==0) days = 0;
    if(temp) printf("%d\n", days);
    else printf("-1\n");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    int a=0,b=0,i,x;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        a+=x;
        if(a>7)
        {
            b+=8;
            a-=8;
        }
        else
        {
            b+=a;
            a=0;
        }
        if(b>=k)
            {
               printf("%d",i);
               return 0;
            }
    }
    printf("-1");
    return 0;
}

#include <stdio.h>

int main()
{
	int n,k,a[105],i,given_candies=0,stored_candies=0,count_days=0,j=0;

	scanf("%d",&n);
	scanf("%d",&k);

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

	while(j<n && given_candies<k)
	{
		if(a[j]>8)
		{
			stored_candies=stored_candies+a[j]-8;
			given_candies=given_candies+8;
			count_days++;
		}
		else
		{
			if(stored_candies>8-a[j])
			{
				given_candies=given_candies+8;
				stored_candies=stored_candies-(8-a[j]);
				count_days++;
			}
			else
			{
				given_candies=given_candies+a[j]+stored_candies;
				stored_candies=0;
				count_days++;
			}
		}
		j++;

	}

	if(given_candies<k)
		printf("-1\n");
	else
		printf("%d",count_days);

}

#include<stdio.h>
#include<stdlib.h>

int main(){
    int n,k;
    scanf("%d",&n);
    scanf("%d",&k);
    int* arr = (int*)malloc(sizeof(int)*n);
    int i=0,x=0,y=0;
    for (i=0;i<n;i++){
        scanf("%d",&arr[i]);
    }
    i =0;
    int sent =0;
    while(i<n){
        x = arr[i] + y;
        if(x<=8){
            y = 0;
            sent+=x;

        }
        else {
            y = x-8;
            sent +=8;
        }
        if(sent >= k){
            printf("%d",i+1);
            return 0;
        }
        i++;
    }
    if(y > 0 || y<=0){
        printf("-1");
    }

}

#include<stdio.h>

int main(void)
{
	int n, k;
	int i, j;
	int in;
	int day = 0;
	int candy = 0;
	int sum = 0;

	scanf("%d %d", &n, &k);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &in);
		candy += in;
		if (candy >= 8)
		{
			sum += 8;
			candy -= 8;
			day++;
			if (sum >= k)
				break;
		}
		else
		{
			sum += candy;
			candy = 0;
			day++;
			if (sum >= k)
				break;
		}

	}
	if (i == n + 1)
		printf("-1");
	else
		printf("%d", day);

	return 0;
}

#include <stdio.h>

int main(){
	int n , k , a , i=0 , j = 0 ;
	scanf("%d", &n) ;
	scanf("%d", &k) ;
	while (i < n && k > 0 ) {
        scanf("%d", &a) ;
        a = a + j ;
        j = 0 ;
        if ( a > 8 ) {
            k = k - 8 ;
            j = a - 8 ;
        }
        else {
            k = k - a ;
        }
        ++i ;
	}
	if ( k <= 0 ) printf("%d", i) ;
	else printf("%d", -1) ;
return 0 ;
}

#include <stdio.h>

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

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

		if (give >= k)
		{
			printf("%d", i);
			return 0;
		}
	}

	printf("-1");

	return 0;
}

#include <stdio.h>

int candy;
int n,k;

int main()
{
    int i,a;

    scanf("%d %d",&n,&k);

    for(i=0;i<n;i++){
        scanf("%d",&a);
        candy+=a;

        if(candy>8){
            k -= 8;
            candy -= 8;
        }
        else{
            k -= candy;
            candy = 0;
        }

        if(k<=0) {
            printf("%d",i+1);
            return 0;
        }
    }

    printf("-1");
    return 0;
}

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

#include<stdio.h>
#include<conio.h>
int main()
{
	int SoNgay, SoKeoCho, Keo, SoKeoDu = 0;
	scanf("%d", &SoNgay);
	scanf("%d", &SoKeoCho);
	int i;
	for ( i = 1; i <= SoNgay; i++)
	{
		scanf("%d", &Keo);
		SoKeoDu = SoKeoDu + Keo;
		if (SoKeoDu > 8)
		{
			SoKeoCho = SoKeoCho - 8;
			SoKeoDu = SoKeoDu - 8;
		}
		else
		{
			SoKeoCho = SoKeoCho - SoKeoDu;
			SoKeoDu = 0;
		}
		if (SoKeoCho <= 0)
			break;
	}
	if (SoKeoCho <= 0)
	{
		printf("%d", i);
	}
	else
	{
		printf("-1");
	}
	return 0;
}

#include <stdio.h>

int main()
{
     int n,k;
 int i=1,sum=0,same=0;
 int ara[100001],bra[100001];
 scanf("%d %d",&n,&k);
  while(n--)
  {
      int a;
      scanf("%d",&a);
      a=a+same;
      if(a<9)
      {
           sum=sum+a;
           same=0;
      }
     else
     {
         sum=sum+8;
         same=a-8;

     }
     if(sum>=k)
     {
          printf("%d\n",i);
       return 0;
     }
     i++;
  }
  printf("-1\n");

}

//http://codeforces.com/contest/839/problem/A
#include<stdio.h>
#include<math.h>
#include<string.h>
#define False 0
#define True 1
// int small(char ch)
// int capital(char ch);
// int prime(int number);
// void bubble_sort(int arr[], int n);
//void upper(char *ptr);
//void lower(char *ptr);
// void sort(char *ptr, int n);
// void RemoveDuplicates(char * arr, char * new_str, int arr_size);
// int Contains(char * arr, char elem, int arr_size);
// int Times_of_shapes(char * str, int len);

int main(void)
{

    int days, order, result=0, i;
    scanf("%d %d", &days, &order);
    int arr[days];
    for(i=0;i<days;i++)
    {
    	scanf("%d", &arr[i]);
    }
    for(i=0;i<days;i++)
    {
    	if(arr[i]>=8)
    	{
    		order-=8;
    		arr[i+1]+=(arr[i]-8);
    		result++;
    	}
    	else
    	{
    		order-=arr[i];
    		result++;

    	}
    	if(order<=0)
    	{
    		break;
    	}
    }
    if(order<=0)
    {
    	printf("%d\n", result);
    }
    else
    	printf("-1\n");
	return 0;
}

// int Times_of_shapes(char * str, int len)
// {

// 	int j, i, times=0, result=0;
// 	str[len]='\0';
// 	char temp[len][len+1];
// 	for(i=0;i<=len;i++)
// 	{
// 		temp[0][i]=str[i];
// 	}
// 	for(i=1;i<len;i++)
// 	{
// 		temp[i][0]=temp[i-1][len-1];
// 		for(j=1;j<len;j++)
// 		{
// 			temp[i][j]=temp[i-1][j-1];
// 		}
// 		temp[i][len]='\0';
// 	}

// 	for(i=0;i<len;i++)
// 	{
// 		times=0;
// 		for(j=i+1;j<len;j++)
// 		{
// 			if(strcmp(temp[i], temp[j])==False)
// 			{
// 				times++;
// 			}
// 		}
// 		if(times==False)
// 		{
// 			result++;
// 		}
// 	}
// 	return result;

// }

// int Contains(char * arr, char elem, int arr_size)
// {

//     int index = 0;

//     for(index = 0; index < arr_size; index++)
//     {

//         if(arr[index] == elem)
//         {
//             return True;
//         }
//     }

//     return False;

// }

// void RemoveDuplicates(char * arr, char * new_str, int arr_size)
// {

//     int index = 0, new_index = 0;

//     //clear temp string
//     for(index = 0; index < arr_size; index++)
//     {
//         new_str[index] = 0;
//     }

//     for(index = 0; index < arr_size; index++)
//     {

//         if(Contains(new_str, arr[index], arr_size) == False)
//         {
//             new_str[new_index] = arr[index];
//             new_index++;
//         }
//         if(index==arr_size-1)
//         {
//             new_str[new_index]='\0';
//         }
//     }

// }

// void sort(char *ptr, int n)
// {
// 	int i, j, temp;
// 	for(i=0;i<n-1;i++)
// 	{
// 		for(j=0;j<n-i-1;j++)
// 		{
// 			if(ptr[j]>ptr[j+1])
// 				{
// 					temp=ptr[j];
// 					ptr[j]=ptr[j+1];
// 					ptr[j+1]=temp;
// 				}

// 		}
// 	}

// }

/*
void upper(char *ptr)
{
	int i=0;
	while(ptr[i]!='\0')
	{
		if(ptr[i]>='a'&&ptr[i]<='z')
			ptr[i]-=32;
		i++;
	}

}*/

/*
void lower(char *ptr)
{
	int i=0;
	while(ptr[i]!='\0')
	{
		if(ptr[i]>='A'&&ptr[i]<='Z')
			ptr[i]+=32;
		i++;
	}
}*/

// void bubble_sort(int ptr[], int n)
// {
// 	int i, j, temp;
// 	for(i=0;i<n-1;i++)
// 	{
// 		for(j=0;j<n-i-1;j++)
// 		{
// 			if(ptr[j]>ptr[j+1])
// 				{
// 					temp=ptr[j];
// 					ptr[j]=ptr[j+1];
// 					ptr[j+1]=temp;
// 				}

// 		}
// 	}

//  }

// int capital(char ch)
// {
// 	int flag=0;
// 	if(ch>=65&&ch<=90)
// 		flag=1;
// 	return flag;

// }

// int small(char ch)
// {
// 	int flag=0;
// 	if(ch>='a'&&ch<='z')
// 		flag=1;
// 	return flag;

// }
// int prime(int number)
// {
// 	int flag=1, i;
// 	for(i=2;i<=number/2;i++)
// 	{
// 		if(number%i==0)
// 		{
// 			flag=0;
// 			break;
// 		}
// 	}
// 	if(number<=1)
// 		flag=1;
// 	return flag;
// }

#include<stdio.h>
#define N 100
int main(){
    int n,k;
    int a[N];
    scanf("%d%d",&n,&k);
    int i;
    int give=0;
    int receive=0;
    int day=0;
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        give+=a[i];
        if(receive>=k){
            break;
        }else{
            if(give>=8){
                receive+=8;
                give-=8;
            }else{
                receive+=give;
                give=0;
            }
            day++;
        }
    }
    if(receive<k){
        printf("%d\n",-1);
    }else{
        printf("%d\n",day);
    }
    return 0;
}

#include <stdio.h>
#define MAXGIVE 8
int min(int x, int y) {
    return x*(x<=y)+y*(x>y);
}
int main() {
    int len,candy,curr,bran=0,saved=0,i=0,keep=1,dar;
    scanf("%d %d\n",&len,&candy);
    while (i<len && keep) {
        scanf("%d",&curr);
        dar=min(curr+saved,MAXGIVE);
        bran+=dar;
        saved=(curr+saved-dar);
        if (bran>=candy) {
            keep=0;
            printf("%d",i+1);
        }
        i++;
    }
    if (keep) printf("-1");
    return 0;
}

#include <stdio.h>
int min(int a, int b) { if(a > b) return b; return a; }
int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
    int d[n];
    for(int i = 0; i < n; i++)
        scanf("%d", &d[i]);
    int lend = 0, addition = 0;
    for(int i = 0; i < n; i++)
    {
        int x = min(8, d[i]);
        if(x < 8)
        {
            lend += 8-x;
            int v = min(8-x, addition);
            x += v;
            addition -= v;
            lend -= v;
        }
        else
            addition += d[i]-8;
        k -= x;
        if(k <= 0)
            return 0*printf("%d\n", i+1);
    }
    puts("-1");
}

#include <stdio.h>

int main(int argc, char** argv) {
	int n, i, ukupno = 0, k, a, tacno = -1;
	scanf("%d %d", &n, &k);
	for(i = 0 ; i < n ; i++){
		scanf("%d", &a);
		if(tacno == -1){

		ukupno += a;
		if(ukupno <= 8){
			k  -= ukupno;
			ukupno = 0;
		}else{
			k -= 8;
			ukupno -= 8;
		}
		if( k <= 0){
			tacno = i+1;
		}
	}
	}
	printf("%d", tacno);
	return 0;
}

#include<stdio.h>
int main()
{
    int n,k,i,j,giv=0;
    scanf("%d %d",&n,&k);
    int a[n+1];
    for(i=0;i<n;i++)
    scanf("%d",&a[i]);
    a[n]=0;
    for(i=0;i<n;i++)
    {
        if(a[i]<8)
        giv+=a[i];
        else {
            giv+=8;
            a[i+1]+=a[i]-8;
        }
        if(giv>=k)
        break;
    }
    if(i==n)
    printf("-1");
    else printf("%d",i+1);
     return 0;

}

#include <stdio.h>
#include <string.h>
int main(){
	int n,k,num=0,t,tmp=0,f=0;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&t);
		t+=tmp;
		tmp=0;
		if(t>8){
			num+=8;
			tmp=t-8;
			f++;
			if(num>=k)
			break;
		}
		else{
		num+=t;
		f++;
		if(num>=k)
		break;
    }
	}
	if(num<k){
		printf("-1");
	}
	else{
		printf("%d",f);
		}
		}

#include<stdio.h>

int main()
{
    int n, k, i, day=0, total=0;
    scanf("%d%d", &n, &k);
    int ara[n];

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

    for(i=0; i<n; i++){
        if(ara[i]+day<=8){
            total=total+ara[i]+day;
            day=0;
        }
        if(ara[i]+day>8){
            total=total+8;
            day=ara[i]+day-8;
        }
        if(total>=k){
            printf("%d\n", i+1);
            return 0;
        }
    }

    printf("-1\n");
    return 0;
}

//https://codeforces.com/problemset/problem/839/A

#include<stdio.h>
int main()
{
    int i,n,k,left=0,count=0,flag=0,h=0;
    int a[1010];
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;;i++){
        if(a[i]<=8){
            h=h+a[i];
            count++;
        }
        else {
            a[i+1]+=(a[i]-8);
            h=h+8;
            count++;
        }
        if(h>=k)break;
    }
    if(count<=n)printf("%d\n",count);
    else printf("-1\n");

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,k,i,j,r=0,c=0,d=0,m=0;
    scanf("%d%d",&n,&k);
    int ar[n];
    for(i=0;i<n;i++)
    scanf("%d",&ar[i]);

    for(i=0;i<n;i++)
    {
            ar[i]+=r;
            if(ar[i]>8)
            {r=abs(ar[i]-8);
            c+=8;}
            else
            {
               r=0;
               c+=ar[i];
            }
            d++;
        if(c>=k)
        {
            m=1;
            break;
        }
    }
    if(m!=1)
    printf("-1");
    else
    printf("%d",d);
}

#include<stdio.h>

int floor(float x)
{
    int floor;
    if(x>=0) floor = (int)x;
    else {
        floor = (int)x;
        if(x - (float)floor ) floor--;
    }

    return floor;
}

int ceil(float x)
{
        int ceil;
    if(x>=0) {
        ceil = (int)x;
        if(x - (float)ceil) ceil++;

    }
    else ceil = (int)x;

    return ceil;

}

int round(float x)
{
    int round;
    if(x<0) x -= .5;
    else x += .5;
    round = (int)x;

    return round;
}

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

    while(given<k && i<n) {

//        remain = 0;
//        for(j=0; j<i; ++j) remain += a[j];
        if(a[i]<8) {
            if(remain+a[i]-8 >= 0) {
                given += 8;
                remain -= 8 - a[i];
//                a[i] = 0;
            }
            else if(remain+a[i]-8 < 0) {
                given += remain+a[i];
                remain = 0;
//                a[i] = 0;
            }
        }
        else if(a[i]>8) {
            given += 8;
            remain += a[i]-8;
        }
        else {
            given += a[i];
//            a[i] = 0;
        }
//        printf("%d %d %d\n", a[i], given, remain);
        i++;

    }
    if(given<k) printf("-1");
    else printf("%d", i);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int n,k,c=0,c1;
	scanf ("%d%d", &n,&k);

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

		if (k<=0){
			printf ("%d", i);
		break;
		}

	}
	if (k>0)
		printf ("-1");

return 0;
}

#include<stdio.h>
#include<math.h>

int main()
{
    int num,k,i;
    scanf("%d%d",&num,&k);
    int ara[num],sum=0;
    for(i=0;i<num;i++)
       {
           scanf("%d",&ara[i]);
           sum=sum+ara[i];
       }
       if(sum<k) printf("-1\n");
       else if(num*8<k) printf("-1\n");
       else
       {
           for(i=1;i<=num;i++)
           {
               if(ara[i-1]<=8) k=k-ara[i-1];
               else if(ara[i-1]>8)
               {
                   k=k-8;
                   ara[i]+=ara[i-1]-8;
               }
               if(k<=0)
                break;
           }
           if(i>num) printf("-1\n");
           else printf("%d\n",i);
       }

    return 0;
}

#include <stdio.h>
#define MIN(x, y) ((x) < (y)? (x): (y))

int main()
{
    int n, k, box = 0, day;
    scanf("%d%d", &n, &k);
    for (day = 1; day <= n; day++) {
        int a;
        scanf("%d", &a);
        box += a;
        int give = MIN(8, box);
        box -= give;
        k -= give;
        if (k <= 0) break;
    }
    printf("%d\n", (k > 0)? -1: day);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

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

    }

    else printf("-1\n");

}

#include <stdio.h>
int main()
{
    int n,k,i,sum,c,remain,flag;
    scanf("%d %d",&n,&k);
    int x[n];
    for(i=0; i<n; i++)
    {
        scanf("%d",&x[i]);
    }
    flag=0;
    sum=0;
    c=0;
    for(i=0; i<n; i++)
    {
        if(x[i]<=8)
        {
            sum=sum+x[i];
            c++;
            if(sum>=k)
            {
                flag=1;
                break;
            }
            else
            {
                flag=0;
            }
        }
        else if(x[i]>8)
        {
            c++;
            sum=sum+8;
            remain=x[i]-8;
            if(sum>=k)
            {
                flag=1;
                break;
            }
            else if(sum<k)
            {
                flag=0;
            }
            if(i+1<n && flag==0)
            {
                x[i+1]=x[i+1]+remain;
            }
        }
    }
    if(flag==1)
    {
        printf("%d",c);
    }
    else if(flag==0)
    {
        printf("-1");
    }
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,k,*a,i,count=0;
	scanf("%d%d",&n,&k);
	a = (int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	i = 0;
	while((k>0)&&(i<n))
	{
		if(a[i]<=8)
			k = k-a[i];
		else
		{
			k = k-8;
			a[i+1] = a[i+1]+(a[i]-8);
		}
		//printf("%d\n",k);
		count++;
		i++;

	}
	if(k<=0)
		printf("%d\n",count);
	else
		printf("-1\n");
	return 0;
}

#include<stdio.h>
int main()
{
    int a[100],i,j,n,m,count=0,sum=0,b,k,l=0;
    scanf("%d %d",&n,&m);
    k=m;
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        a[i]=a[i]+l;
        if(a[i]==m&&a[i]==8)
        {
            count=count+1;
            b=8;
           // printf("%d %d\n",count,b);
        }
        else if(a[i]>=8)
        {
            count=count+1;
            b=8;
            l=a[i]-8;
         // printf("d=%d %d\n",count,b);
        }
        else
        {
            m=m-a[i];
            count=count+1;
            b=a[i];
            l=0;
           // printf("e=%d %d\n",count,b);
        }

        sum=sum+b;
        if(sum>=k)
        {
            break;
        }
    }
    //printf("%d",sum);
    if(count==0||sum<k)
    {
        printf("-1");
    }
    else{
    printf("%d\n",count);}

}

#include<stdio.h>

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

#include<stdio.h>
int main()
{
	int n,k,i,s=0,b,j=0;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&b);
		j=j+b;
		if(j>=8)
		{
			s=s+8;
			j=j-8;
		}
		else
		{
			s=s+j;
			j=0;
		}
		if(s>=k)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	printf("-1\n");
	return 0;
 }

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdlib.h>

int main() {
	int n, k;
	while(scanf("%d %d", &n, &k)==2) {
		int s=0, g=0, i;
		for(i=0; i<n && g<k; i++) {
			int x;
			scanf("%d", &x);
			s += x;
			if (s>=8) g+=8, s-=8;
			else g+=s, s=0;
		}
		if (g<k) printf("%d\n", -1);
		else printf("%d\n", i);
		break;
	}
}

#include<stdio.h>

int main()
{
    int n, k, i, day=0, total=0;
    scanf("%d%d", &n, &k);
    int ara[n];

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

    for(i=0; i<n; i++){
        if(ara[i]+day<=8){
            total=total+ara[i]+day;
            day=0;
        }
        if(ara[i]+day>8){
            total=total+8;
            day=ara[i]+day-8;
        }
        if(total>=k){
            printf("%d\n", i+1);
            return 0;
        }
    }

    printf("-1\n");
    return 0;
}

#include<stdio.h>
int main()
{
int n,k,i,count=0,l=0,m,mul=0,save=0;
scanf("%d",&n);
int arr[n];
scanf("%d",&k);
m=k;
for (i=0 ;i<n ;i++)
{
    scanf("%d",&arr[i]);
    mul +=arr[i];
    }
    for (i=0 ; i<n ; i++)
        {

if(n*8<k || k>mul)
{
printf("-1\n");
break;
}
else
    {
if(arr[i]>8 && m>8)
{
m= m-8;
count +=8;
save =arr[i]-8;
arr[i+1] +=save;
l++;
}
else
{
if(arr[i]>m)
{
count +=m;
l++;
}
else
{
    if(m>arr[i]){
m= m-arr[i];
count +=arr[i];
l++;}
else
{
    count +=m;
    l++;
}
}
}}
if(m==0 || count==k)
{
printf("%d\n",l);
l = 0;
break;
}
}
if (l!=0)
    printf("-1");

return 0;
 }

#include<stdio.h>
int main()
{
    int n,k,s,a,q=-1,m=0,p=1;
    scanf("%d %d",&n,&k);
    s=0;
    while(p<=n)
    {
        scanf("%d",&a);
        s=s+a;
        if(s>8) { m=m+8;  s=s-8;  }
        else { m=m+s; s=0; }
        if( m>=k ) { q=p; break; }
        p++;
    }
    printf("%d",q);
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}

int main()
{
	int i,n,k,a[1005],sum=0,temp=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);

	}
	for(i=0;i<n;i++)
	{
		if(a[i]>=8)
		{
			sum+=8;
			temp+=(a[i]-8);
		}
		else
		{
			temp+=a[i];
			if(temp>=8)
			{
				temp-=8;
				sum+=8;
			}
			else
			{
				sum+=temp;
				temp=0;
			}
		}
		if(sum>=k)
			break;
	}
	if(sum>=k)
	{
		printf("%d\n",i+1);
	}
	else
	{
		printf("-1\n");
	}

	return 0;

}

/*
 * A. Arya and Bran
 * time limit per test
 * 1 second
 * memory limit per test
 * 256 megabytes
 * input
 * standard input
 * output
 * standard output
 *
 * 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.
 * Input
 *
 * 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).
 * Output
 *
 * If it is impossible for Arya to give Bran k candies within n days, print -1.
 *
 * Otherwise print a single integer — the minimum number of days Arya needs to give Bran k candies before the end of the n-th day.
 * Examples
 * Input
 *
 * 2 3
 * 1 2
 *
 * Output
 *
 * 2
 *
 * Input
 *
 * 3 17
 * 10 10 10
 *
 * Output
 *
 * 3
 *
 * Input
 *
 * 1 9
 * 10
 *
 * Output
 *
 * -1
 *
 *  Note
 *
 *  In the first sample, Arya can give Bran 3 candies in 2 days.
 *
 *  In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
 *
 *  In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies within 1 day.
 */

#include <stdio.h>
int main() {
    int i, n, k, num, a_candy, b_candy;
    scanf("%d %d", &n, &k);
    for(i = 0, a_candy = b_candy = 0; i < n && b_candy < k; i++) {
        scanf("%d", &num);
        a_candy += num;
        if(a_candy >= 8) {
           a_candy -= 8;
           b_candy += 8;
        } else {
           b_candy += a_candy;
           a_candy = 0;
        }
    }
    if(i == n && b_candy < k)
        printf("-1");
    else
        printf("%d", i);
    return 0;
}

#include<stdio.h>

int main()
{
    int n=0;
	int	k=0;
	int last=0;
	int sum=0;
	int i;
	int a[20000];

	scanf("%d %d ",&n,&k);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if (a[i]+last>=8)
		{
			sum+=8;
            last=last+a[i]-8;
		}
		else if (a[i]+last<8)
		{
			 sum=sum+last+a[i];
             last=0;
		}
		if (sum >= k)
		{
			printf("%d",i);
			return 0;
		}
	}

	printf("-1");
	return 0;

}

#include<stdio.h>

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

    for(i=0; i<=n; i++)
    {
        if(i==n)
        {
            printf("-1");
            break;
        }

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

}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    int sum = 0;
    int sum2 = 0;
    int i;
    for ( i = 0; i < a; i++)
    {
        int k;
        scanf("%d", &k);
        if (k >= 8)
        {
            sum2 += k - 8;
            sum += 8;
        }
        else
        {
            if (sum2 > (8-k))
            {
                sum2 -= 8-k;
                sum += 8;
            }
            else
            {
                sum +=sum2 + k;
                sum2 = 0;
            }
        }
        //printf("sum = %d   sum2 = %d\n",sum,sum2);
        if ( sum >= b)
        {
            sum =0;
            break;
        }
    }
    if (sum != 0 )
    {
        printf("-1");
    }
    else
    {
        printf("%d",++i);
    }
}

#include<stdio.h>
#include<math.h>
int main()
{
    int n,k,i,a=0,b=0,c=0,d=0;
    scanf("%d %d",&n,&k);
    int ar[n];
    for(i=0;i<n;i++)
    scanf("%d",&ar[i]);

    for(i=0;i<n;i++)
    {
        while(a<k)
        {
            if(ar[i]==8)
            {
                a+=ar[i];
                b+=1;
                break;
            }
            else if(ar[i]<8)
            {
                if(ar[i]+c>=8)
                {
                a+=8;
                c=c-(8-ar[i]);
                b+=1;
                break;
                }
                else
                {
                a+=(ar[i]+c);
                c=0;
                b+=1;
                break;
                }
            }
            else
            {
                a+=8;
                c+=ar[i]-8;
                b+=1;
                break;
            }
        }
    }
    if(a<k)
    printf("-1");
    else
    printf("%d",b);
    return 0;
}

#include <stdio.h>

int main(void)
{
    int i, n, k, a[100], bram = 0;

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

    for(i = 0; i < n; i++)
    {
        if(a[i] < 8)
            bram += a[i];
        else
        {
            bram += 8;
            if(i < n)
                a[i+1] += a[i] - 8;
        }

        if(bram >= k)
            break;
    }

    (i < n)? printf("%d\n", i+1) : printf("%d\n", -1);
}

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int n,k,t,brian=0,arya=0;
	scanf("%d %d",&n,&k);
	int a[n];
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int i;
	t=n;
	for(i=0;i<n;i++)
	{
		arya+=a[i];
		if(arya>=8)
			{
				k-=8;
				arya-=8;
			}
		else
			{
				k-=arya;
				arya=0;
			}
		if(k<=0)
			{
				printf("%d",i+1);
				return 0;
			}
	}
	printf("-1");
	return 0;
}

#include <stdio.h>

int main() {
    int n,x[100],k;
    scanf("%d %d",&n,&k);
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    int s=0,count=1;
    for(i=0;i<n;i++){
        if(x[i]<=8) s=s+x[i];
        else{
            s=s+8;
            x[i+1]=x[i+1]+x[i]-8;
        }
        if(s>=k) {
            printf("%d",count);
            return 0;
        }
        count++;
    }
    printf("-1");
	return 0;
}

#include<stdio.h>

int main(void)
{
    int N,K,Count,Day=0,Total=0;
    scanf("%d%d",&N,&K);
    int Array[N];
    for(Count=0;Count<N;Count++)
        scanf("%d",&Array[Count]);
    for(Count=0;Count<N;Count++)
    {
        if(K<=0)
            break;
        if(Array[Count]>8)
        {
            K-=8;
            Total+=(Array[Count]-8);
        }
        else
        {
            K-=Array[Count];
            if(Total>=(8-Array[Count]))
            {
                K-=(8-Array[Count]);
                Total-=(8-Array[Count]);
            }
            else
            {
                K-=Total;
                Total=0;
            }
        }
        Day++;
    }
    if(K<=0)
        printf("%d\n",Day);
    else
        printf("%d\n",-1);
    return 0;
}

#include <stdio.h>

int main()
{
	int n,k,a[105],candies_given=0,store=0,i,count=0,j=0;

	scanf("%d",&n);
	scanf("%d",&k);

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

	while(candies_given<k && j<n)
	{
		if(a[j]>8)
		{
			candies_given=candies_given+8;
			store=store+a[j]-8;
			j++;
			count++;
		}
		else
		{
			a[j]=a[j]+store;
			if(a[j]>8)
			{
				candies_given=candies_given+8;
				store=a[j]-8;
				j++;
				count++;
			}
			else
			{
				candies_given=candies_given+a[j];
				j++;
				store=0;
				count++;
			}

		}
	}

	if(candies_given<k && j==n)
		printf("-1\n");
	else
		printf("%d",count);
}

#include<stdio.h>

int main()
{
    int a[101],i,sum=0,s=0,n,m,count=0;
    scanf("%d %d",&n,&m);

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

    }
    for(i=0;i<n;i++)
    {   if(m>s)
    {   if(a[i]>=8)
        {
            count++;
        }
        else
        {
            if(a[i]>=8)
                continue;

            else
                sum+=a[i];
        }

    }
        else
            break;

    }
    if((sum+(count*8))>=m)
    printf("%d",i);

   else
       printf("-1");
return 0;

   // printf("%d %d",count,sum);

}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <string.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
    int a[n];
	for(int i=0;i<n;i=i+1){
		scanf("%d",&a[i]);
	}
	int count=0;
	for(int i=0;i<n-1;i=i+1){
		if(a[i]<=8&&k>0){
			k=k-a[i];
		}else if(a[i]>8&&k>0){
			k=k-8;
			a[i+1]+=a[i]-8;
		}
		count+=1;
	}
	if(a[n-1]>8){
		a[n-1]=8;
	}
	if(k>0){
		k=k-a[n-1];
		count+=1;
	}
	if(k<=0){
		printf("%d",count);
		return 0;
	}
	printf("-1");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i,sum=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(sum<k)
        {
            if(a[i]>8)
            {
                a[i+1] = a[i+1]+(a[i]-8);
                sum = sum +8;
            }
            else
            {
                sum = a[i];
            }
        }
        else
        {
            break;
        }
    }

    if(sum<k)
        printf("%d",-1);
    else
    printf("%d",i);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,k,i,c=0,t=0;
    scanf("%d %d",&n,&k);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
     for(i=0;i<n,t<k;i++){
            if(a[i]>8){
                t=t+8;
                a[i+1]=a[i+1]+a[i]-8;
        }
            else
                t=t+a[i];
    }
if(k>t)
    printf("-1");
else
    printf("%d",i);
    return 0;
}

#include<stdio.h>
int main()
{
     int n,k,i,r=0,x=0,p=0;
     scanf("%d %d",&n,&k);
     int ara[n];
     for(i=0; i<n ;i++)
     {
          scanf("%d",&ara[i]);
          ara[i]=x+ara[i];
         if(ara[i]>8 )
          {
               ara[i]=8;
               x=ara[i]-8;

          }
          else x=0;
          p=ara[i]+p;

          r++;
          if(p>=k)
               break;
     }
     if(r<=n && p>=k)
          printf("%d",i+1);
     else
          printf("-1");
     return 0;
}

#include<stdio.h>
int main()
{
    int n,k,s,a,c=0,m=0,p;
    scanf("%d %d",&n,&k);
    s=k;
    while(n--)
    {
        scanf("%d",&a);
        if(a>8) s=s-8;
        else s=s-a;
        c++;
        if(s<=0&&c>m) { m=c; c=0; }
    }
    if(s>0) printf("-1");
    else printf("%d",m);
}

#include <stdio.h>

int main()
{
    int n, k, count = 0, a;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; ++i) {
        scanf("%d", &a);
        count += a > 8 ? 8 : a;
        if(count >= k) {
            printf("%d\n", i + 1);
            return 0;
        }
    }
    puts("-1");
    return 0;
}

#include<stdio.h>

int main(){
    int n,k,i,j,count=0,x=-1;
    scanf("%d %d",&n,&k);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d ",&a[i]);
    }

    j=0;
    while(k>0 && (j<n)){
        if(a[j]>8){
            k=k-8;
            count++;
            j++;
        }

        else if(a[j]<=8){
            k=k-a[j];
            count++;
            j++;
        }

    }
    if(j=n){

    if(k<=0){
    printf("%d",count);
    }

    else printf("%d",x);

    i=j=count=0;

}
}

#include<stdio.h>
int main()
{
    int c[100];
    int k,i,n,sum=0,count=0;
    float r,f;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
    }
    if(n*8<k)
    {
        printf("-1");
    }
    else
    {
        for(i=0;i<n;i++)
        {
            if(sum<k)
            {
                sum=sum+c[i];
                count=count+1;

            }
        }

        if(count*8<=k)
        {
            r=k/8;
            f=(float)k/8;
            if(f>r)
            {
                printf("%d",(int)f+1);
            }
            else
            {
                printf("%d",(int)r);
            }

        }
        else
        {
            printf("%d",count);
        }

    }
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main() {
	int n, k, i, sum = 0;
	scanf("%d%d", &n, &k);
	int x;
	for(i = 1; i <= n; i++){
		scanf("%d", &x);
		if(x >= 8)
			x = 8;
		sum = sum + x;
		if(sum >= k){
			printf("%d\n", i);
			exit(0);
		}
	}
	printf("-1\n");
	return 0;
}

#include <stdio.h>

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	int s = 0;
     int i;
	for (i=1; i<=n; i++)
	{
	     int a;
	     scanf("%d", &a);
	     s = (a>8)?(s+8):(s+a);
	     if (s>=k) break;
	}
	if (s>=k)
	     printf("%d", i);
	else
	     printf("-1");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int ll;
typedef long double ld;

#define FOR(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define ROF(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define rep(i,n)   for(int (i) = 0; (i) < (n); ++(i))
int MAX(int a, int b) {
	return (a>b)?a:b;
}
int main(int argc, char const *argv[]) {
	int n,k;
	scanf("%d%d",&n,&k);
	int *arr = (int*)calloc(n,sizeof(int));
	rep(i,n)scanf("%d",&arr[i]);
	int ans = 0, rem = 0;
	rep(i,n) {
		ans = i;
		if (arr[i]>8) {
			rem+=arr[i]-8;
			k-=8;
		} else {
			rem+=arr[i];
			if (rem>8) {
				rem-=8;
				k-=8;
			} else {
				rem=0;
				k-=rem;
			}
		}
		if (k<=0)
			break;
	}
	if (k>0)
		printf("-1\n");
	else
		printf("%d\n", ans+1);
	return 0;
}

#include<stdio.h>
int main()
{
    int n,k,temp=-1;
    scanf("%d %d",&n,&k);
    int arr[n];
    int i,sum=0;
    for(i=0;i<n;i++){
        scanf("%d",&arr[i]);
        if(arr[i]>8) sum+=8;
        else sum+=arr[i];
        if(sum>=k) temp=i+1;
    }

    printf("%d",temp);
}

#include<stdio.h>
int main()
{
    int c[100];
    int k,i,n,sum=0,count=0;
    float r,f;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&c[i]);
    }
    if(n*8<k)
    {
        printf("-1");
    }
    else
    {
        for(i=0;i<n;i++)
        {
            if(sum<k)
            {
                sum=sum+c[i];
                count=count+1;

            }
        }
        printf("%d ",count);
        if(count*8<k)
        {
            r=k/8;
            f=(float)k/8;
            if(f>r)
            {
                printf("%d",(int)f+1);
            }
            else
            {
                printf("%d",(int)r);
            }

        }
        else
        {
            printf("%d",count);
        }

    }
}

#include<stdio.h>

int main(void)
{
    int N,K,Count,Day=0;
    scanf("%d%d",&N,&K);
    int Array[N];
    for(Count=0;Count<N;Count++)
        scanf("%d",&Array[Count]);
    for(Count=0;Count<N;Count++)
    {
        if(K<=0)
            break;
        if(Array[Count]>8)
            K-=8;
        else
            K-=Array[Count];
        Day++;
    }
    if(K<=0)
        printf("%d\n",Day);
    else
        printf("%d\n",-1);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,k,a,i,sum=0,x=0,r,c=0;
    scanf("%d %d",&n,&k);

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

        scanf("%d",&a);
        sum=sum+a+x;
         if(n*8<k)
    {
        printf("-1");
        return 0;
    }

        else if(sum<=k)
        {
            if(sum>8)
            {
                x=sum-8;
            }
            else
            {
                x=0;
            }
        }
c++;

    }
    printf("%d",c);
    return 0;
}

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

#include<stdio.h>
int main ()
{
    int n,k,a[1010],count=0,rem=0,i,flag=0;
    scanf("%d%d",&n,&k);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0; i<n; i++)
    {
        if((rem+a[i])>=8)
        {
            rem=(rem+a[i])-8;
            k=k-8;
            count++;

        }
        else if(k==(rem+a[i])) {
            count++;
            flag=count;
            break;
        }
        else
        {
            k=k-a[i];
            count++;

        }

        if(k<=0)
        {
            flag=count;
            break;
        }

       // printf("DEBUG ==>\nday left =%d\nk left=%d\ncount = %d\nflag =%d\n",n,k,count,flag);

    }
     //printf("%d\n\n\n",flag);
    if(flag>0)printf("%d\n",flag);
    else printf("-1\n");

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int n,k;
   scanf("%d %d",&n,&k);
   int i,p[n],sum=0;
   for(i=0;i<n;i++){
    scanf("%d",p+i);
       sum+=p[i];
   }
    if(8*n>=k){
            int l=0,c=0;
        while(1){
            l+=8;c++;
            sum+=-8;
            if(l>=k){
                printf("%d",c);
                break;
            }
        }
    }

    else printf("-1\n");

}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int n,k,*A;
	scanf ("%d%d", &n,&k);
	A = (int *) malloc ((n+1)*sizeof(int));
	for (int i=1;i<=n;i++)
		scanf ("%d", &A[i]);
	if ((k%8) +1 <= n)
		printf ("%d",n);

return 0;
}

#include <stdio.h>
int main()
{
    int n,k,a,i=0,j,m=0,x;
    scanf("%d%d",&n,&k);
    while(n--)
    {
        scanf("%d",&a);
        x=x+a+m;
        if(x<=8)
            k=k-x;
        else if(x>=8)
            {
                k=k-8;
                m=x-8;
                }
            i++;
        if(k<=0)
        j=i;
        }
        if(k<=0) printf("%d",j);
        else
        printf("-1");
}

#include<stdio.h>
#include<string.h>
int cmpfunc (const void * a, const void * b)
{
    return ( *(int*)a - *(int*)b );
}

main()
{
    int n, k, i, j;
    long long sum = 0, cnt = 0;
    int a[n];
    scanf("%d %d", &n, &k);
    for(i = 0; i<n; i++)
    {
        scanf("%d", &a[i]);
        sum += a[i];
        if(sum>8)
        {
            cnt +=  8;
            sum = sum - 8;
        }
        else
        {
            cnt += a[i];
            sum -= a[i];
        }

        if(cnt>=k)
        {
            printf("%d", i+1);
            return 0;
        }
    }

    printf("-1");

}

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int n, k, a, nDay=0;
	// k = numero de doces desejado
	// n = numero de dias
	// a = qtde de doce do dia

	int i, tot=0, sobra=0;

	scanf("%d", &n);
	scanf("%d", &k);

	for(i=0; i<n; i++) {
		scanf("%d", &a);
		a = a+sobra;
		if(a>8) {
			a=a-8;
			sobra+=a;
			tot += 8;
		}
		else {
			tot += a;
		}
		nDay++;
		if(tot==k) break;
	}
	if(tot>=k)
		printf("%d\n", nDay);
	else
		printf("-1\n");

	return 0;
}

#include<stdio.h>
int main ()
{

    int n,k,i,j,sum,d;
    while(scanf("%d %d",&n,&k)!=EOF)
    {
        sum=d=0;
        int array[n];
    for(i=0;i<n;i++)
    {

        scanf("%d",&array[i]);
    }
    for(i=0;i<n;i++)
    {
        if(array[i]>=8)
          sum+=8;
        else
         sum+=array[i];
        if(sum>=k)
        {
            d=i+1;
            break;
        }

    }
    if(d)
        printf("%d\n",d);
    else
        printf("-1\n");

    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main(){
	int n,k,A[10000];
	scanf ("%d%d", &n,&k);

	for (int i=1;i<=n;i++){
		scanf ("%d", &A[i]);
		if (A[i] >=8) A[i] = 8;
		k-=A[i];

		if (k<=0)
			printf ("%d", i);

	}
	if (k>0)
		printf ("-1");

return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,t,i;
    int s=0;
    int a [100];
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);

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

        if(a[i]>=8)
            {
                s=s+8;
            a[i+1]+= a[i]-8;
    }
    else
        s=s+a[i];
    if(s>=k)
    {
        t=i+1;
        break;
    }

     }

    printf ("%d",t);
}

#include <stdio.h>

#define N 100

int main() {
	static int aa[N];
	int n, k, i, b, r, cnt, yes;

	scanf("%d%d", &n, &k);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	yes = cnt = b = r = 0;
	for (i = 0; i < n; i++) {
		b += (aa[i] + r <= 8 ? aa[i] : 8);
		if (aa[i] > 8)
			r += aa[i] - 8;
		cnt++;
		if (b >= k) {
			yes = 1;
			break;
		}
	}
	if (!yes)
		if ((b + r) >= k) {
			yes = 1;
			cnt += (r + 7) / 8;
		}
	printf("%d\n", yes && cnt <= n ? cnt : -1);
	return 0;
}

#include <stdio.h>
#include <math.h>
#define N 1000

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

#include <stdio.h>

int main()
{
	int n,k,a[105],candies_given=0,store=0,i,count=0,j=0;

	scanf("%d",&n);
	scanf("%d",&k);

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

	while(candies_given<=k && j<n)
	{
		if(a[j]>8)
		{
			candies_given=candies_given+8;
			store=store+a[j]-8;
			j++;
			count++;
		}
		else
		{
			a[j]=a[j]+store;
			if(a[j]>8)
			{
				candies_given=candies_given+8;
				store=a[j]-8;
				j++;
				count++;
			}
			else
			{
				candies_given=candies_given+a[j];
				j++;
				store=0;
				count++;
			}

		}
	}

	if(candies_given<k && j==n)
		printf("-1\n");
	else
		printf("%d",count);
}

#include <stdio.h>

int main()

{
    int n,k,i,a,count=0,c=0,b=0;
    scanf(" %d %d",&n,&k);

    for(i=0;i<n;i++)
    {
        scanf(" %d",&a);
        a=a+b;
        printf(" %d %d\n",a,c);

        if(a<8 && c<k){
            c+=a;
            b=0;
            count++;
        }
        else if(c<k){
            c+=8;
            b=a-8;
            count++;
        }
    }

    if(c>=k)
        printf("%d\n",count);
    else
        printf("-1");

    return 0;
}

#include <stdio.h>

int main()
{
	int n,k,a[105],i,given_candies=0,stored_candies=0,count_days=0,j=0;

	scanf("%d",&n);
	scanf("%d",&k);

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

	while(j<n)
	{
		if(a[j]>8)
		{
			stored_candies=stored_candies+a[j]-8;
			given_candies=given_candies+8;
			count_days++;
		}
		else
		{
			if(stored_candies>8-a[j])
			{
				given_candies=given_candies+8;
				stored_candies=stored_candies-(8-a[j]);
				count_days++;
			}
			else
			{
				given_candies=given_candies+a[j]+stored_candies;
				stored_candies=0;
				count_days++;
			}
		}
		j++;

	}

	if(given_candies<k)
		printf("-1\n");
	else
		printf("%d",count_days);

}

#include<stdio.h>
int main()
{
int n,k,r=0;
scanf("%d %d",&n,&k);
int a[n];
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]<=8)
{
r=a[i]+r;
printf("day :%d r=%d\n",i+1,r);
}
else
{
r=8+r;
printf("day :%d r=%d\n",i+1,r);
}
if(r>=k)
{
int rem=r-k;
if(rem!=0)
{
for(int j=0;j<n;j++)
{
if(a[j]==rem)
{
printf("%d\n",i);
return 0;
}
}
}
printf("R=%d\n",r);
printf("%d\n",i+1);
return 0;
}
}

printf("-1\n");
}

#include<stdio.h>
int main ()
{
    int n,k,a[1010],count=0,rem=0,i,flag=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
       }
    for(i=0;i<n;i++){
        if((rem+a[i])>8){
        rem=a[i]-8;
        k=k-8;
        count++;

       }
       else{
        k=k-a[i];
         count++;

       }
       if(k<=0){flag=count;
       break;
       }

    }
    if(flag>0)printf("%d\n",flag);
    else printf("-1\n");

    return 0;
}

#include<stdio.h>
int main()
{
    int n,k,i,j,m,ar[10000];
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&ar[i]);
    }
    if(n*8 <k)
        printf("-1\n");
    else
    {
        for(i=0;i<n;i++)
        {
            if(ar[i]<8)
                k=k-ar[i];
            else
                k=k-8;
        }
        if(k<=0)
            printf("%d\n",i);
        else
            printf("-1\n");

    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int n,k;
   scanf("%d %d",&n,&k);
   int i,p[n],sum=0;
   for(i=0;i<n;i++){
    scanf("%d",p+i);
       sum+=p[i];
   }
    if(8*n>=k){
            int l=0,c=0;
        while(c<n&&sum!=0){
            l+=8;c++;
            sum+=-8;
            if(l>=k)break;
        }
        if(l>=k)printf("%d",c);
        else printf("-1");
    }

    else printf("-1\n");

}

#include<stdio.h>
int main()
{
int n,k,i,count=0,l=0,m;
scanf("%d",&n);
int arr[n];
scanf("%d",&k);
m=k;
for (i=0 ;i<n ;i++)
{
    scanf("%d",&arr[i]);
    }
    for (i=0 ; i<n ; i++)
        {

if(n*8<k)
{
printf("-1\n");
break;
}
else
    {
if(arr[i]>8 && m>8)
{
m= m-8;
count +=8;
l++;
}
else
{
if(arr[i]>m)
{
count +=m;
l++;
}
else
{
    if(m>arr[i]){
m= m-arr[i];
count +=arr[i];
l++;}
else
{
    count +=m;
    l++;
}
}
}}
if(m==0 || count==k)
{
printf("%d\n",l);
break;
}

}
return 0;
 }

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <string.h>
int main(int argc, char const *argv[])
{
	int n,k;
	scanf("%d %d",&n,&k);
    int a[n];
	for(int i=0;i<n;i=i+1){
		scanf("%d",&a[i]);
	}
	int count=0;
	for(int i=0;i<n-1;i=i+1){
		if(a[i]>8){
			a[i]=8;
			a[i+1]+=a[i]-8;
		}
	}
	if(a[n-1]>8){
		a[n-1]=8;
	}
	for(int i=0;i<n;i=i+1){
		if(k>0){
			k-=a[i];
			count+=1;
		}
	}
	if(k>0){
		printf("-1\n");
		return 0;
	}
	printf("%d",count);
	return 0;
}

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

#include<stdio.h>
int main ()
{
	int n,k,x,sum=0,m=0,b=0;
	scanf("%d%d",&n,&k);
	int i;

	for (i=1;i<=n;i++){
		scanf("%d",&x);
		if (x==0)
		break;
		x+=b;
		if (x>8){
			b=x-8;
			 x=8;
		}
		sum+=x;
		m++;
		if (sum>=k) break;
	}

	if (sum>=k) printf("%d\n",m);
	else printf("-1");
	return 0;

}

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,k,*a,i,count=0;
	scanf("%d%d",&n,&k);
	a = (int *)malloc(sizeof(int)*n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	i = 0;
	while((k>0)&&(i<n))
	{
		if(k<=8)
			k = k-a[i];
		else
		{
			k = k-8;
			a[i+1] = a[i+1]+(a[i]-8);
		}
		//printf("%d\n",k);
		count++;
		i++;

	}
	if(k<=0)
		printf("%d\n",count);
	else
		printf("-1\n");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int n, k, a=0, nDay=0;
	// k = numero de doces desejado
	// n = numero de dias
	// a = qtde de doce do dia

	int i, tot=0, sobra=0;

	scanf("%d", &n);
	scanf("%d", &k);

	for(i=0; i<n; i++) {
		scanf("%d", &a);
		sobra += a;
		if(sobra>=8) {
			sobra-=8;
			k-=8;
		}
		else {
			k -= a;
			sobra = 0;
		}
		nDay++;
		if(k<=0) break;
	}
	if(k<=0) printf("%d\n", nDay);
	else printf("-1\n");

	return 0;
}

#include<stdio.h>
int main()
{
    int a[100],i,j,n,m,count=0,sum=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]==m&&a[i]==8)
        {
            count=count+1;
        }
        else if(a[i]>=8&&n!=1)
        {
            m=m-8;
            count=count+1;

        }
        else if(a[i]<8)
        {
            m=m-a[i];
            count=count+1;
        }
        sum=sum+a[i];
    }
    if(count==0||sum<m)
    {
        printf("-1");
    }
    else{
    printf("%d\n",count);}

}

#include<stdio.h>
main()
{
    int n,k,a[10000],i,j,sum=0,flag=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]>8)a[i]=8;
        }
        for(i=0;i<n;i++)
        {
            sum=sum+a[i];
            if(sum>=k)
            {
                printf("%d\n",i+1);flag=1;break;
            }
        }
    if(flag==0)printf("-1\n");
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n, k, candy, days=0, i, ans=0, temp=0, remain=0;
    scanf("%d%d", &n, &k);
    for(i=0; i<n; i++){
        scanf("%d", &candy);
        candy+=remain;
        if(candy<=8) ans+=candy;
        else{
            remain = candy-8;
            ans+=8;
        }
        days++;
        if(ans>=k){
            temp=1;
            break;
        }
    }
    if(k==0) days = 0;
    if(temp) printf("%d\n", days);
    else printf("-1\n");
    return 0;
}

#include<stdio.h>
int main()
{
     int n,k,i,r=0,x=0,p=0;
     scanf("%d %d",&n,&k);
     int ara[n];
     for(i=0; i<n ;i++)
     {
          scanf("%d",&ara[i]);
          ara[i]=x+ara[i];
         if(ara[i]>8 )
          {
               x=ara[i];
               ara[i]=8;

          }
          else x=0;
          p=ara[i]+p;

          r++;
          if(p>=k)
               break;
     }
     if(r<=n && p>=k)
          printf("%d",i+1);
     else
          printf("-1");
     return 0;
}

//Name: Bui Minh Khoa
//Code: 1753005
//Ex 839A

#include <stdio.h>

int main()
{
	int day, candy, a,give=0,spare=0,time=1;
	scanf("%d %d", &day, &candy);

	for (; day > 0; day--)
	{
		scanf("%d", &a);
		if (a >= 8)
		{
			give = give + 8;
			spare = spare + a - 8;
		}
		else
			give = give + a;
		if (give < candy)
			time++;
		else
			break;
	}
	if (give < candy)
		printf("-1");
	else
		printf("%d", time);

	return 0;
}

#include <stdio.h>

int main()

{
    int n,k,i,a,count=0,c=0,b=0;
    scanf(" %d %d",&n,&k);

    for(i=0;i<n;i++)
    {
        scanf(" %d",&a);
        a=a+b;

        if(a<8 && c<k){
            c+=a;
            count++;
        }
        else if(c<k){
            c+=8;
            b=a-8;
            count++;
        }
    }

    if(c>=k)
        printf("%d\n",count);
    else
        printf("-1");

    return 0;
}

#include<stdio.h>
int main()
{
int n,k,a[100],i=0,sum=0;
scanf("%d %d",&n,&k);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
}
while(n!=0)
{
    sum=sum+8;
    if(sum>=k)
    {
        printf("%d",i);
        break;
    }n--;
}
if(sum<k)
{
    printf("-1");
}
return 0;
}

#include<stdio.h>
int main ()
{
    int n,k,a[1010],count=0,rem=0,i,flag=0;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
       }
    for(i=0;i<n;i++){
        if((rem+a[i])>=8){
        rem=(rem+a[i])-8;
        k=k-8;
        count++;

       }
       else{
        k=k-a[i];
         count++;

       }
       if(k<=0){flag=count;
       break;
       }

    }
    if(flag>0)printf("%d\n",flag);
    else printf("-1\n");

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i,sum=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(sum<k)
        {
            if(a[i]>8)
            {
                a[i+1] = a[i+1]+(a[i]-8);
                sum = sum +8;
            }
            else
            {
                sum = a[i];
            }
        }
        else
        {
            break;
        }
    }

    if(sum<k)
        printf("%d",-1);
    else
    printf("%d",i);
    return 0;
}

#include<stdio.h>
int a[100005];
int main()
{
    int n,k,i;
    int flag=0;
    scanf("%d%d",&n,&k);
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);

    for(i=1;i<=n;i++)
    {
         if(a[i]>8)
        {
            k-=8;
        }
        else k-=a[i];
        if(k<=0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
        printf("%d\n",i);
    else printf("-1\n");

    return 0;

}

#include <stdio.h>
int main()
{
    int n,k,a,i=0,j,m=0,x;
    scanf("%d%d",&n,&k);
    while(n--)
    {
        scanf("%d",&a);
        x=x+a+m;
        if(x<=8)
            k=k-x;
        else if(x>=8)
            {
                k=k-8;
                m=x-8;
                }
            i++;
        if(k<=0)
        j=i;
        }
        if(k<=0) printf("%d",j);
        else
        printf("-1");
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int cmp(const void *a,const void *b)
{
	return *(int *)a-*(int *)b;
}

int main()
{
	int i,n,k,a[1005],sum=0,temp=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);

	}
	for(i=0;i<n;i++)
	{
		if(a[i]>=8)
		{
			sum+=8;
			temp+=(a[i]-8);
		}
		else
		{
			temp+=a[i];
			if(a[i]>=8)
			{
				temp-=8;
				sum+=8;
			}
			else
			{
				sum+=temp;
				temp=0;
			}
		}
		if(sum>=k)
			break;
	}
	if(sum>=k)
	{
		printf("%d\n",i+1);
	}
	else
	{
		printf("-1\n");
	}

	return 0;

}

//Name: Bui Minh Khoa
//Code: 1753005
//Ex 839A

#include <stdio.h>

int main()
{
	int day, candy, a, give = 0, spare = 0, time = 1;
	scanf("%d %d", &day, &candy);

	for (; day > 0; day--)
	{
		scanf("%d", &a);
		if (a > 8)
		{
			give = give + 8;
			spare = spare + a - 8;
		}
		else
		{
			give = give + a;
			if (spare+a > 8)
				give = give + 8-a;
			else
				give = give + spare;
		}
		if (give < candy)
			time++;
		else
			break;
	}
	if (give < candy || time<day)
		printf("-1");
	else
		printf("%d", time);

	return 0;
}

#include <stdio.h>

int main(void)
{
	int n, k, a, sum, d, i;
	scanf("%d %d", &n, &k);

	d = -1;
	for(i=1; i<=n; i++)	{
		scanf("%d", &a);
		if(d==-1)	{
		if(a<=8)	{
			k -= a;
			a = 8-a;
			if(a<=sum)	{
				k -= a;
				sum -= a;
			}
			else {
				k -= sum;
				sum = 0;
			}
		}
		else {
			k -= 8;
			a -= 8;
			sum += a;
		}
		if(k<=0)	d = i;
	}
	}

	printf("%d\n", d);

	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    int sum = 0;
    int sum2 = 0;
    int i;
    for ( i = 0; i < a; i++)
    {
        int k;
        scanf("%d", &k);
        if (k > 8)
        {
            sum2 = k - 8;
            sum += 8;
        }
        else
        {
            if (sum2 > (8-k))
            {
                sum2 -= 8-k;
                sum += 8;
            }
            else
            {
                sum +=sum2 + k;
                sum2 = 0;
            }
        }
        //printf("sum = %d\n",sum);
        if ( sum >= b)
        {
            sum =0;
            break;
        }
    }
    if (sum != 0 )
    {
        printf("-1");
    }
    else
    {
        printf("%d",++i);
    }
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,k,i,NoOfCandy[100],FlagDone=0,DailyCandy=0;
    scanf("%d %d ",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&NoOfCandy[i]);
    }
    for(i=0;i<n;i++){
      if(NoOfCandy[i]<8){
        DailyCandy+=NoOfCandy;
        }
       else {
        DailyCandy+=8;
        }
        if(DailyCandy>=k){
            printf("%d",i+1);
            FlagDone=1;
            break;
        }
    }
    if(FlagDone==0){
        printf("-1");
    }
    return 0;
}

#include<stdio.h>
#include<conio.h>

int main() {

	int n, k, a[100];
	scanf("%d", &n);
	scanf("%d", &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	int temp = n;
	int dem = 0;
	for (int i = 0; i < n; i++)
	{
		if (k > 0 && temp > 0)
		{
			if (a[i] > 8) {
				k = k - 8;
				temp--;
				if (temp == 0 && k > 0) {
					dem = 0;
				}
				else
				{
					dem++;
				}
			}
			else
			{
				k = k - a[i];
				temp--;
				if (temp == 0 && k > 0) {
					dem = 0;
				}
				else
				{
					dem++;
				}
			}
		}
	}
	if (dem == 0)
	{
		printf("-1");
	}
	else
	{
		printf("%d", dem);
	}
	return 0;
}

#include <stdio.h>

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

#include <stdio.h>
int main()
{
    int i, j, n, k;
    scanf("%d %d", &n, &k);
    int a[n];
    for(i=0; i<n; ++i) {
        scanf("%d", &a[i]);
    }
    int given = 0, remain = 0;
    i = 0;

    while(given<k && i<n) {

        remain = 0;
        for(j=0; j<i; ++j) remain += a[j];
        if(a[i]<8) {
            if(remain+a[i]-8 >= 0) {
                given += 8;
                remain -= 8 - a[i];
                a[i] = 0;
            }
            else if(remain+a[i]-8 < 0) {
                given += remain+a[i];
                remain = 0;
                a[i] = 0;
            }
        }
        else if(a[i]>8) {
            given += 8;
            a[i] -= 8;
        }
        else {
            given += a[i];
            a[i] = 0;
        }
        i++;

    }
    if(given<k) printf("-1");
    else printf("%d", i);

    return 0;
}

#pragma warning(disable:4996)
#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define forn(i,n) for (i = 0; i<n; i++)

int lol(const void *x1, const void *x2)
{
	return *(int*)x1 - *(int*)x2;
}

int gcd(int a, int b)
{
	int c;
	while (b)
	{
		c = a % b;
		a = b;
		b = c;
	}
	return a;
}
int main(void)
{
	int n, k, i, t, sber = 0;
	int day, temp;
	scanf("%i%i", &n, &k);
	forn(i, n)
	{
		scanf("%i", &t);
		if (t > 8)
		{
			sber += t - 8;
			t = 8;
		}
		else
		{
			temp = 8 - t;
			if (sber >= temp)
			{
				t += temp;
				sber -= temp;
			}
			else
			{
				t += sber;
				sber = 0;
			}
		}
		k -= t;
		if (k <= 0)
			day = i + 1;
	}
	if (k > 0)
		day = -1;
	printf("%i", day);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#define maxn 105
int a[maxn];
int main()
{
    int n,k,i,count_k=0,days=0,temp=0;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {

        if(a[i]>=8)
        {
            count_k+=8;
            temp=temp+a[i]-8;
        }
        else if(a[i]+temp>=8)
        {
            temp=temp-8;
            count_k+=8;
        }
        else count_k+=a[i];
        days++;
        if(count_k>=k)
        {
            printf("%d\n",days);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}

#include <stdio.h>
int min(int a,int b){return (a<b)?a:b;}
int main()
{
    int i,n,k;
    scanf("%d%d",&n,&k);
    int left=k;
    int total=0;
    for(i=0;i<n;i++)
    {
        int ele;
        scanf("%d",&ele);
        total+=ele;
        left-=min(total,8);
        if(left<=0) break;
    }
    if(left>0) printf("-1\n");
    else printf("%d\n",i+1);
    return 0;
}

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

#include<stdio.h>

int main(void) {
	int n, k, sum = 0, rem = 0;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		int box;
		scanf("%d", &box);
		if (box > 8) {
			sum += 8;
			rem += box - 8;
		}
		else {
			sum += box;
		}

		if (sum >= k) {
			printf("%d", i);
			return 0;
		}
	}
	printf("-1");
}

#include<stdio.h>
#include<math.h>

int main()
{
    int num,k,i;
    scanf("%d%d",&num,&k);
    int ara[num],sum=0;
    for(i=0;i<num;i++)
       {
           scanf("%d",&ara[i]);
           sum=sum+ara[i];
       }
       if(sum<k) printf("-1\n");
       else if(num*8<k) printf("-1\n");
       else
       {
           for(i=1;i<=num;i++)
           {
               if(ara[i-1]<=8) k=k-ara[i-1];
               else if(ara[i-1]>8)
               {
                   k=k-8;
                   ara[i]+=ara[i-1]%8;
               }
               if(k<=0)
                break;
           }
           printf("%d\n",i);
       }

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
long long int cmpfunc( const void *a, const void *b) {
  return *(long long int*)a - *(long long int *)b;
}

int main()
{
 long long int test,d,n,x,i,sum=0,count=0,j,flag=0,p,y,m,max=0,o,g,r,k, a[1000000],sum1=0;
scanf("%lld%lld",&n,&m);
count=0;
sum=0;
sum1=0;
for(i=0;i<n;i++){
  scanf("%lld",&a[i]);
  if(a[i]>=8){
      sum+=8;
      sum1+=a[i]-8;
      count++;
  }else{

      sum+=a[i];
      if(8-a[i]<=sum1){
          sum+=8-a[i];
          sum1-=8-a[i];
      }
      count++;
  }
  if(sum>=m){
      break;
  }

}

if(sum>=m){
    printf("%lld",count);
}else{
    printf("-1");
}
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main() {
	int n, k, i, sum = 0;
	scanf("%d%d", &n, &k);
	int x;
	int r = 0;
	for(i = 1; i <= n; i++){
		scanf("%d", &x);
		x = x + r;
		if(x >= 8){
			r = x - 8;
			x = 8;
		}
		sum = sum + x;
		if(sum >= k){
			printf("%d\n", i);
			exit(0);
		}
	}
	printf("-1\n");
	return 0;
}


#include <stdio.h>

int main(){

	int n, m;
	scanf("%d %d", &n, &m);

	if(n < m){
		int tmp;
		tmp = n, n = m, m = tmp;
	}

	printf("%d %d\n", --n, m);

	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char str1[500000],str2[500000];
	int m, n;
	scanf("%d %d", &n, &m);
	int i, j, k;
	int countRed=n, countBlue=m;
	str1[0]='r';
	for(i=1;i<=m+n;i++)
	{
		if(i%2==1)
		{
			if(str1[i-1]=='r')
			{
				if(countRed>0)
				{
					str1[i]='r';
					countRed--;
				}
				else
				{
					str1[i]='b';
					countBlue--;
				}
			}
			else if(str1[i-1]=='b')
			{
				if(countBlue>0)
				{
					str1[i]='b';
					countBlue--;
				}
				else
				{
					str1[i]='r';
					countRed--;
				}
			}
		}
		else
		{
			if(str1[i-1]=='r')
			{
				if(countBlue>0)
				{
					str1[i]='b';
					countBlue--;
				}
				else
				{
					str1[i]='r';
					countRed--;
				}
			}
			else if(str1[i-1]=='b')
			{
				if(countRed>0)
				{
					str1[i]='r';
					countRed--;
				}
				else
				{
					str1[i]='b';
					countBlue--;
				}
			}
		}
	}
	str2[0]='b';
	countBlue=m;countRed=n;
	for(i=1;i<=m+n;i++)
	{
		if(i%2==1)
		{
			if(str2[i-1]=='b')
			{
				if(countBlue>0)
				{
					str2[i]='b';
					countBlue--;
				}
				else
				{
					str2[i]='r';
					countRed--;
				}
			}
			else if(str2[i-1]=='r')
			{
				if(countRed>0)
				{
					str2[i]='r';
					countRed--;
				}
				else
				{
					str2[i]='b';
					countBlue--;
				}
			}
		}
		else
		{
			if(str2[i-1]=='b')
			{
				if(countRed>0)
				{
					str2[i]='r';
					countRed--;
				}
				else
				{	str2[i]='b';
					countBlue--;
				}
			}
			else if(str2[i-1]=='r')
			{
				if(countBlue>0)
				{
					str2[i]='b';
					countBlue--;
				}
				else
				{	str2[i]='r';
					countRed--;
				}
			}
		}
	}
	int count1=0, count2=0,count3=0, count4=0;
	//printf("%s %s",str1, str2);
	for(i=1;i<strlen(str1)-1;i++)
	{
		if(str1[i]==str1[i+1])
		 count1++;
		else
			count3++;
		if(str2[i]==str2[i+1])
			count2++;
		else
			count4++;
	}
	if(count1>count2)
		printf("%d %d\n",count1, count3);
	else
		printf("%d %d\n",count2, count4);
	return 0;
}

#include <stdio.h>

int main(void) {
 					int pet,vas,n,m,min,max;
 					scanf("%d %d",&n,&m);
 					max=n>m?n:m;
 					min=n>m?m:n;
 					pet=max-1-(max%2&&!min%2?1:0);
 					vas=min+(max%2&&!min%2?1:0);
 					printf("%d %d\n",pet,vas);
	return 0;
}

#include <stdio.h>

void func(int ln, int lm, int last, int *_ps, int *_vs)
{
    int ps, vs, t;
    ps = vs = t = 0;
    while (ln > 0 || lm > 0)
    {
        if (t == 0)
        {
            if (last == 0)
            {
                if (lm > 0)
                {
                    last = 1;
                    vs ++;
                    lm --;
                }
                else
                {
                    ps ++;
                    ln --;
                }
            }
            else
            {
                if (ln > 0)
                {
                    last = 0;
                    vs ++;
                    ln --;
                }
                else
                {
                    ps ++;
                    lm --;
                }
            }
        }
        else
        {
            if (last == 0)
            {
                if (ln > 0)
                {
                    ps ++;
                    ln --;
                }
                else
                {
                    last = 1;
                    vs ++;
                    lm --;
                }
            }
            else
            {
                if (lm > 0)
                {
                    ps ++;
                    lm --;
                }
                else
                {
                    last = 0;
                    vs ++;
                    ln --;
                }
            }
        }
        t = 1 - t;
    }
    *_ps = ps;
    *_vs = vs;
}

void solve(int n, int m)
{
    int ps, vs, px, vx;
    func(n - 1, m, 0, &ps, &vs);
    func(n, m - 1, 1, &px, &vx);
    if (ps > px)
    {
        printf("%d %d\n", ps, vs);
    }
    else if (ps < px)
    {
        printf("%d %d\n", px, vx);
    }
    else if (vs < vx)
    {
        printf("%d %d\n", ps, vs);
    }
    else
    {
        printf("%d %d\n", px, vx);
    }
}

int main()
{
    int n, m;
    while (scanf("%d%d", &n, &m) == 2)
    {
        solve(n, m);
    }
    return 0;
}

#include<stdio.h>
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	if(n>m)
	printf("%d %d",n-1,m);
	else
	printf("%d %d",m-1,n);
	return 0;
}

#include <stdio.h>

int main() {
    int n, m;
    int s1, s2;
    scanf("%d %d", &n, &m);

    s2 = n < m ? n : m;
    s1 = n + m - s2 - 1;
    printf("%d %d\n", s1, s2);
    return 0;
}

#include <stdio.h>

#define MAXN 100002

#define R 0x1
#define B 0x2

unsigned char balls[MAXN+MAXN];

void solve(int prev, int r, int b, int *s1, int *s2) {
	int turn = 0x1;
	int curr;
	if (prev == R) r--;
	else b--;
	*s1 = 0;
	*s2 = 0;
	while (r + b > 0) {
		if (turn == 0) {
			if (prev == R) {
				if (r > 0) {
					r--;
					curr = R;
				}
				else if (b > 0) {
					b--;
					curr = B;
				}
			} else {
				if (b > 0) {
					b--;
					curr = B;
				} else if (r > 0) {
					r--;
					curr = R;
				}
			}
		} else {
			if (prev == R) {
				if (b > 0) {
					b--;
					curr = B;
				} else if (r > 0) {
					r--;
					curr = R;
				}
			} else {
				if (r > 0) {
					r--;
					curr = R;
				} else if (b > 0) {
					b--;
					curr = B;
				}
			}
		}

		if (prev == curr) ++(*s1);
		else ++(*s2);
		turn ^= 0x1;
		prev = curr;
	}
}

int main() {
	int s1, s2;
	int s3, s4;
	int r, b;
	scanf("%d %d", &r, &b);

	solve(R, r, b, &s1, &s2);
	solve(B, r, b, &s3, &s4);
	if (s1 > s3) {
		printf("%d %d\n", s1, s2);
	} else {
		printf("%d %d\n", s3, s4);
	}
	return 0;
}

#include <stdio.h>

int main() {
  int blue, red; //number of blue cubes, red cubes left
  scanf("%d %d", &red, &blue);
  int i;

  //blue first
  int blue_b = blue, red_b = red;
  int same_b = 0, diff_b = 0; //peter = same, vasya = diff

  char prev = 'b';
  blue_b--;

  for(i = 1; i < blue+red; i++) {
    if(i % 2 == 1) { //vasya's turn, wants different
      if(prev == 'b') {
	if(red_b > 0) {
	  red_b--;
	  prev = 'r';
	  diff_b++;
	}
	else{
	  blue_b--;
	  same_b++;
	}
      }
      else if(prev == 'r') {
	if(blue_b > 0) {
	  blue_b--;
	  prev = 'b';
	  diff_b++;
	}
	else {
	  red_b--;
	  same_b++;
	}
      }
    }

    if(i % 2 == 0) { //petya's turn, wants same
      if(prev == 'r') {
	if(red_b > 0) {
	  red_b--;
	  same_b++;
	}
	else {
	  blue_b--;
	  diff_b++;
	  prev = 'b';
	}
      }
      else if(prev == 'b') {
	if(blue_b > 0) {
	  blue_b--;
	  same_b++;
	}
	else {
	  red_b--;
	  diff_b++;
	  prev = 'r';
	}
      }
    }
  }

  //red first
  int blue_r = blue, red_r = red;
  int same_r = 0, diff_r = 0; //peter = same, vasya = diff

  prev = 'r';
  red_r--;

  for(i = 1; i < blue+red; i++) {
    if(i % 2 == 1) { //vasya's turn, wants different
      if(prev == 'b') {
	if(red_r > 0) {
	  red_r--;
	  prev = 'r';
	  diff_r++;
	}
	else{
	  blue_r--;
	  same_r++;
	}
      }
      else if(prev == 'r') {
	if(blue_r > 0) {
	  blue_r--;
	  prev = 'b';
	  diff_r++;
	}
	else {
	  red_r--;
	  same_r++;
	}
      }
    }

    if(i % 2 == 0) { //petya's turn, wants same
      if(prev == 'r') {
	if(red_r > 0) {
	  red_r--;
	  same_r++;
	}
	else {
	  blue_r--;
	  diff_r++;
	  prev = 'b';
	}
      }
      else if(prev == 'b') {
	if(blue_r > 0) {
	  blue_r--;
	  same_r++;
	}
	else {
	  red_r--;
	  diff_r++;
	  prev = 'r';
	}
      }
    }
  }

  if(same_r > same_b) {
    printf("%d %d", same_r, diff_r);
  }
  else {
    printf("%d %d", same_b, diff_b);
  }
  return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n>m)
    {
        printf("%d %d",n-1,m);
    }
    else
    {
        printf("%d %d",m-1,n);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    int a,b,g,s;
    scanf("%d %d",&a,&b);
    g=(a>b?a:b);
    s=(a<=b?a:b);
    printf("%d %d",g-1,s);
    return 0;
}

#include<stdio.h>
main(){
	long int n,m;
	scanf("%ld%ld",&n,&m);//n-->red m-->blue cubes
	if(n>m){
		printf("%ld %ld",n-1,m);
	}else{
		printf("%ld %ld",m-1,n);
	}
}

#include<stdio.h>

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	if(n > m)
		printf("%d %d\n", n - 1, m);
	else printf("%d %d\n", m - 1, n);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int n,m;
int main()
{
    scanf("%i %i",&n,&m);
    int m1,m2;
    if (n<=m)
    {
        m1=n;m2=m;
    }
    else{m1=m;m2=n;}
    printf("%i %i",m2-1,m1);

    return 0;
}

#include<stdio.h>
int main()
{
int m,n,a,b;
scanf("%d %d",&n,&m);
if(n>m)
{a=n-1;
b=m;
}
else
{a=m-1;
b=n;
}
printf("%d %d",a,b);
}

#include <stdio.h>

int main()
{
    int N,M ;
    scanf("%d %d",&N,&M);
    if(N>=M)
    {
        printf("%d %d\n",N-1,M);
    }
    else
    {
        printf("%d %d\n",M-1,N);
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int out,diff;
	if(m<n){
		out=m;
		diff = n-m;
	}
	else{
		out = n;
		diff = m-n;
	}
	printf("%d %d\n",out+diff-1,out);

	return 0;
}

#include <stdio.h>

int n, m;

void calc(int m, int n, int prev, int *a, int *b)
{
    int i, u = 0, v = 0;
    int c[2];
    c[0] = m; c[1] = n;

    for (i = 1; i <= m + n; ++i)
    {
        if ((i & 1) == 1)
        {
            if (c[!prev] > 0)
            {
                prev = !prev;
                ++v;
            }
            else ++u;
            --c[prev];
        }
        else
        {
            if (c[prev] > 0) ++u;
            else
            {
                prev = !prev;
                ++v;
            }
            --c[prev];
        }
    }

    *a = u;
    *b = v;
}

int main(void)
{
    int i, a, b, c, d;
    scanf("%d%d", &n, &m);

    calc(m - 1, n, 0, &a, &b);
    calc(m, n - 1, 1, &c, &d);

    if (a > c) printf("%d %d\n", a, b);
    else printf("%d %d\n", c, d);

    return 0;
}

#include<stdio.h>
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    if(n>m)
      printf("%d %d\n",n-1,m);
      else printf("%d %d\n",m-1,n);
    return 0;
}

#include<stdio.h>
int main()
{
    int i,n,m,x,y;
    scanf("%d%d",&n,&m);
    x=n>m?n:m;
    y=n<m?n:m;
    printf("%d %d",2*(y/2)+(x-2*(y/2)-1),y);
    return 0;
}

#include <stdio.h>
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    if(n>=m)
        printf("%d %d",n-1,m);
    else
        printf("%d %d",m-1,n);
   return 0;
}

#include<stdio.h>
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n>=m)
    printf("%d %d\n",n-1,m);
    else
    printf("%d %d\n",m-1,n);
    return 0;

}

#include<stdio.h>
int main()
{
	long long int n,m,min,total=0,petya,vasya;
	scanf("%lld%lld",&n,&m);
	if(n<=m)
	{
		//printf("*");
		min=n;
		//printf("%lld\n",min);
	}
	else
		min=m;
	total=n+m-1;
	//printf("%lld\n",total);
	petya=total-min;
	vasya=min;
	printf("%lld %lld\n",petya,vasya);
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

static void swap (void *u, void *v, size_t n) {
  char *r = u, *s = v, t;
  while (n-- > 0) {
    t = *r;
    *r++ = *s;
    *s++ = t;
  }
}

int main (void) {
  int r, n, m, s1 = 0, s2 = 0;
  scanf ("%d %d\n", &n, &m);
  if (m > n)
    swap (&n, &m, sizeof n);
  --m; r = 1;
  while (n > 0 || m > 0) {
    --n; --m;
    if (n >= 0) {
      if (r == 0)
        ++s1;
      else
        ++s2;
      r = 0;
    }

    if (m >= 0) {
      if (r == 0)
        ++s1;
      else
        ++s2;
      r = 1;
    }
  }
  printf ("%d %d\n", s1, s2);
  exit (EXIT_SUCCESS);
}

#include<stdio.h>
int main()
{
    int t,white,black,opposite;
        scanf("%d%d",&black,&white);
        //Minimum of both ball goes to Aaquib's Points and remaining will make pair with Prashant as both play equally good
        opposite=black<white?black:white;
        printf("%d %d\n",black+white-1-opposite,opposite);
    return 0;
}

#include <stdio.h>
int main()
{
    int n,m,i,j,k,ans1,ans2,min,max;
    scanf("%d",&n);
    scanf("%d",&m);
    if(n<m)
    {
        min=n;
        max=m;
    }
    else
    {
        min=m;
        max=n;
    }
    max--;
    ans2=min;
    ans1=min/2;
    ans1+=(min/2)-1;
    max=max-2*((min/2)-1);
    ans1+=max-1;
    printf("%d %d\n",ans1,ans2);
    return 0;
}

#include <stdio.h>
int main()
{
    int n,m,i,j,k,ans1,ans2,min,max;
    scanf("%d",&n);
    scanf("%d",&m);
    if(n<m)
    {
        min=n;
        max=m;
    }
    else
    {
        min=m;
        max=n;
    }
    max--;
    ans2=min;
    ans1=min/2;
    ans1+=(min/2)-1;
    max=max-2*((min/2)-1);
    ans1+=max-1;
    printf("%d %d",ans1,ans2);
    return 0;
}

#include<stdio.h>

int main()
{
    int *arr, i, j, n, m, k, temp, rem, acnt=0, bcnt=0;
    scanf("%d%d", &n, &m);

    if(n > m)
    {
        temp = n;
        n = m;
        m = temp;
    }
    acnt = m - 1;
    bcnt = n;
    printf("%d %d", acnt, bcnt);
    return 0;
}

#include<stdio.h>

main()
{
    int petya,vasya,r,b;
    scanf(" %d %d",&r,&b);
    if(r>b)
    vasya=b;
    else
    vasya=r;
    petya=r+b-vasya-1;
    printf("%d %d\n",petya,vasya);
    return 0;
}

#include<stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);

    if(a>b)
        printf("%d %d\n",a-1,b);
    else
        printf("%d %d\n",b-1,a);

    return 0;
}

#include<stdio.h>
#define min(a,b) ((a<b)?a:b);
int main()
{
    int n,m,ans;
    scanf("%d%d",&n,&m);
    ans=min(n,m);
    printf("%d %d",n+m-1-ans,ans);
    return 0;
}

#include <stdio.h>

int main()
{
	int m,n,min,max;
	scanf("%d %d",&m,&n);
	max=m;
	min=n;
	if (n>max){
		max=n;
		min=m;
	}
	printf("%d %d",max-1,min);
	return 0;
}

#include<stdio.h>

int main()
{
    int n,m,i,temp,p=0,v=0;
    scanf("%d%d",&m,&n);

    if(m>n)
    {
        temp=m;m=n;n=temp;
    }
    p+=m-1;v+=m;
    //if(m%2)
    {
        p+=n-m;
    }

    printf("%d %d\n",p,v);
    return(0);
}

#include<stdio.h>

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    n >= m ? printf("%d %d",n-1, m) : printf("%d %d",m-1, n);
    return 0;
}

#include<stdio.h>
int main()
{
    int m,n,t;
    scanf("%d %d",&m,&n);
    if(m<n)
   {

    t=m;
    m=n;
    n=t;}
    printf("%d %d\n",m-1,n);

    return 0;
}

#include <stdio.h>
#include <stdlib.h>

int a,b,x;
int main(){
	scanf("%d %d", &a,&b);
	x=(a>b)?b:a;
	printf("%d %d", a+b-1-x, x);
	return 0;
}

main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    if(n>m)     printf("%d %d\n",n-1,m);
    else    printf("%d %d\n",m-1,n);
    return 0;
}

#include <stdio.h>

char ans[1234567];

int main(){

	int n, m;
	scanf("%d%d", &n, &m);

	int cnt = 0, nn = n, mm = m;

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

		if(i == 0){
			if(nn < mm && nn){
				ans[cnt++] = 'r';
				--nn;
			}
			else{
				ans[cnt++] = 'b';
				--mm;
			}
			continue;
		}

		if(i & 1){
			if(ans[i - 1] == 'r'){
				if(mm){
					ans[cnt++] = 'b';
					--mm;
				}
				else{
					ans[cnt++] = 'r';
					--nn;
				}
			}
			else{
				if(nn){
					ans[cnt++] = 'r';
					--nn;
				}
				else{
					ans[cnt++] = 'b';
					--mm;
				}
			}
		}

		else{
			if(ans[i - 1] == 'r'){
				if(nn){
					ans[cnt++] = 'r';
					--nn;
				}
				else{
					ans[cnt++] = 'b';
					--mm;
				}
			}
			else{
				if(mm){
					ans[cnt++] ='b';
					--mm;
				}
				else{
					ans[cnt++] = 'r';
					--nn;
				}
			}
		}

	}

	int a = 0, b = 0;
	for(int i = 0; i < cnt - 1; i++){
		if(ans[i] == ans[i + 1]){
			++a;
		}
		else{
			++b;
		}
	}

	printf("%d %d\n", a, b);

	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char str1[500000],str2[500000];
	int m, n;
	scanf("%d %d", &n, &m);
	int i, j, k;
	int countRed=n, countBlue=m;
	str1[0]='r';
	for(i=1;i<=m+n;i++)
	{
		if(i%2==1)
		{
			if(str1[i-1]=='r')
			{
				if(countRed>0)
				{
					str1[i]='r';
					countRed--;
				}
				else
				{
					str1[i]='b';
					countBlue--;
				}
			}
			else if(str1[i-1]=='b')
			{
				if(countBlue>0)
				{
					str1[i]='b';
					countBlue--;
				}
				else
				{
					str1[i]='r';
					countRed--;
				}
			}
		}
		else
		{
			if(str1[i-1]=='r')
			{
				if(countBlue>0)
				{
					str1[i]='b';
					countBlue--;
				}
				else
				{
					str1[i]='r';
					countRed--;
				}
			}
			else if(str1[i-1]=='b')
			{
				if(countRed>0)
				{
					str1[i]='r';
					countRed--;
				}
				else
				{
					str1[i]='b';
					countBlue--;
				}
			}
		}
	}
	str2[0]='b';
	for(i=1;i<=m+n;i++)
	{
		if(i%2==1)
		{
			if(str2[i-1]=='b')
			{
				if(countBlue>0)
				{
					str2[i]='b';
					countBlue--;
				}
				else
				{
					str2[i]='r';
					countRed--;
				}
			}
			else if(str2[i-1]=='r')
			{
				if(countRed>0)
				{
					str2[i]='r';
					countRed--;
				}
				else
				{
					str2[i]='b';
					countBlue--;
				}
			}
		}
		else
		{
			if(str2[i-1]=='b')
			{
				if(countRed>0)
				{
					str2[i]='r';
					countRed--;
				}
				else
				{	str2[i]='b';
					countBlue--;
				}
			}
			else if(str2[i-1]=='r')
			{
				if(countBlue>0)
				{
					str2[i]='b';
					countBlue--;
				}
				else
				{	str2[i]='r';
					countRed--;
				}
			}
		}
	}
	int count1=0, count2=0,count3=0, count4=0;
	for(i=1;i<strlen(str1)-1;i++)
	{
		if(str1[i]==str1[i+1])
		 count1++;
		else
			count3++;
		if(str2[i]==str2[i+1])
			count2++;
		else
			count4++;
	}
	if(count1>count2)
		printf("%d %d\n",count1, count3);
	else
		printf("%d %d\n",count2, count4);
	return 0;
}

#include <stdio.h>

#define MAXN 100002

#define R 0x1
#define B 0x2

unsigned char balls[MAXN+MAXN];

void solve(int r, int b) {
	int turn = 0;
	int n = r + b;
	int i = 0;
	int c1 = 0;
	int c2 = 0;
	while (r + b > 0) {
		if (turn == 0) {
			/* Petya */
			if (i > 0) {
				if (balls[i-1] == R) {
					if (r > 0) {
						balls[i] = R;
						r--;
					} else if (b > 0) {
						b--;
						balls[i] = B;
					}
				} else {
					if (b > 0) {
						b--;
						balls[i] = B;
					} else if (r > 0) {
						r--;
						balls[i] = R;
					}
				}
			} else {
				if (r == 1) {
					balls[i] == R;
					r--;
				} else if (b == 1) {
					balls[i] == B;
					b--;
				} else if (r > b) {
					balls[i] = R;
					r--;
				} else if (b > r) {
					balls[i] = B;
					b--;
				}
			}

		} else {
			if (balls[i-1] == R) {
				if (b > 0) {
					b--;
					balls[i] = B;
				} else if (r > 0) {
					r--;
					balls[i] = R;
				}
			} else {
				if (r > 0) {
					r--;
					balls[i] = R;

				} else if (b > 0) {
					b--;
					balls[i] = B;
				}
			}
		}
		turn ^= 0x1;
		i++;
	}

	for (i = 1;i < n; i++) {
		if (balls[i-1] == balls[i]) {
			c1++;
		} else {
			c2++;
		}
	}
	printf("%d %d\n", c1, c2);
}

int main() {
	int r, b;
	scanf("%d %d", &r, &b);
	solve(r, b);
	return 0;
}

#include<stdio.h>
int main()
{int n,k,m,a,b,i,j,ans1=0,ans2=0;
scanf("%d %d",&n,&m);
k=n+m;
if(n>=m)
a=n;
else
a=m;
int arr[k];
for(i=0;i<k;i++)
{if(i<a)
arr[i]=1;
else
arr[i]=0;

}

for(i=0;i<k;i++)
{
if(arr[i]==arr[i+1]&&arr[i]==1)
ans1++;

}
if(m==1)
    ans2==1;
else
ans2=m/2;
printf("%d %d",ans1,ans2);
return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main (void) {
  int A[2], B[2], C[2], dx[2], dy[2];
  long long cp;
  scanf ("%d %d %d %d %d %d", A, A+1, B, B+1, C, C+1);
  dx[0] = B[0] - A[0]; dx[1] = C[0] - B[0];
  dy[0] = B[1] - A[1]; dy[1] = C[1] - B[1];
  cp = (long long) dy[1]*dx[0] - (long long) dy[0]*dx[1];
  printf ("%s\n", cp < 0 ? "RIGHT" : cp == 0 ? "TOWARDS" : "LEFT");
  exit (EXIT_SUCCESS);
}

#include <stdio.h>
#include <stdlib.h>

int main (void) {
  int n, suf[] = {170,20,200,110,50,80}, P = sizeof suf / sizeof *suf;
  scanf ("%d", &n);

  if (n < 3)
    printf ("-1\n");
  else if (n == 3)
    printf ("210\n");
  else
    printf ("1%.*d%.*d\n", n - 4, 0, 3, suf[n % P]);

  exit (EXIT_SUCCESS);
}

#include<stdio.h>
int main()
{
    int t,white,black,opposite;
    scanf("%d",&t);
        scanf("%d%d",&black,&white);
        //Minimum of both ball goes to Aaquib's Points and remaining will make pair with Prashant as both play equally good
        opposite=black<white?black:white;
        printf("%d %d\n",black+white-1-opposite,opposite);
    return 0;
}