#include <bits/stdc++.h>
using namespace std;
long long a[110];
int main() {
  long long n, k, i, arey = 0, bran;
  scanf("%I64d %I64d", &n, &bran);
  for (i = 1; i <= n; i++) scanf("%I64d", a + i);
  for (i = 1; i <= n; i++) {
    if (bran <= 0) break;
    arey += a[i];
    bran -= min(8LL, arey);
    arey -= min(8LL, arey);
  }
  if (bran > 0) i = 0;
  printf("%I64d\n", i - 1);
  return 0;
}
