/*
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int[] answer = {};
return answer;
}
}
public class Main {
public Main() {
Scanner s = new Scanner(System.in);
int[] x = new int[100];
int[] y = new int[100];
int[] count = new int[100];
for(int i=0; i<100; i++) {
x[i] = s.nextInt();
}
for(int i=0; i<100; i++) {
y[i] = s.nextInt();
}
for(int i=0; i<100; i++) {
while(x[i]==100) {
x[i] += y[i];
count[i] ++;
}
}
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.util.*;
class stack{
int top;
int [] stack;
int size;
int count = 0;
private int x;
public stack(int size) {
this.size = size;
stack = new int[size];
top = -1;
}
public void push(int x) {
stack[++top] = x;
}
public void pop() {
stack[top--] = 0;
}
public void compare() {
int ptr =0;
int k=0;
int i=ptr;
while(ptr<top) {
while(stack[ptr]<=stack[i]) {
count ++;
i++;
if(stack[ptr]>stack[i]||i==top) {
stack[k]=count;
k++;
System.out.print(count);
break;
}
}
count = 0;
ptr ++;
i=ptr;
}
System.out.print(0);
}
}
public class Main{
public Main() {
Scanner x = new Scanner(System.in);
String str = x.nextLine();
int [] answer = {};
String[] str1 = new String[str.length()];
str1 = str.split(",");
stack s = new stack(10000);
answer = s.stack;
for(int i=0; i<str1.length; i++) {
s.push(Integer.valueOf(str1[i]));
}
s.compare();
System.out.print(answer);
}
public static void main(String[] args) {
new Main();
}
}
*/
/*
import java.util.*;
class stack{
int[] stk;
int ptr;
int capacity;
int length;
int limit;
public stack(int max, int length, int weight) {
capacity = max;
ptr = 0;
stk = new int[max];
this.length = length;
this.limit = weight; // 다리가 버틸 수 있는 무게
}
public void push(int x) {
stk[ptr++]=x;
stack1 stk1 = new stack1(length,limit);
while(ptr>=0) {
stk1.push(stk[ptr-1]);
}
this.pop();
}
public void pop() {
stk[--ptr]=0;
}
public class Main{
public Main() {
Scanner s = new Scanner(System.in);
int weights = s.nextInt(); // 트럭별 무게
int length = s.nextInt(); // 다리를 건널 수 있는 트럭의 개수
int weight = s.nextInt();// 다리가 버틸 수 있는 무게
stack stk = new stack(weights,length,weight);
int [] x = new int[weights];
for(int i=weights-1; i>=0; i--) {
x[i] = s.nextInt();
stk.push(x[i]);
}
}
public static void main(String[] args) {
new Main();
}
}*/
/*
import java.util.*;
public class Main {
public Main() {
Scanner s = new Scanner(System.in);
int weights = s.nextInt(); // 트럭별 무게
int length = s.nextInt(); // 다리를 건널 수 있는 트럭의 개수
int weight = s.nextInt();// 다리가 버틸 수 있는 무게
stack stk = new stack(weights,length,weight);
int [] x = new int[weights];
for(int i=weights-1; i>=0; i--) {
x[i] = s.nextInt();
stk.push(x[i]);
}
}
public static void main(String[] args) {
new Main();
}
}
class stack{
int[] stk;
int ptr,capacity,limit,length;
public stack(int max, int length, int weight) {
this.capacity = max;
this.limit = weight;
this.length = length;
ptr = 0;
stk = new int[max];
}
public void push(int x) {
if(ptr==0) stk[ptr++]=x;
else {
int sum=0;
for(int i=0; i<ptr; i++) {
sum+=stk[i];
}
if(limit-sum>=x) {
stk[ptr+1]=stk[ptr];
stk[ptr++]=x;
sum=0;
}else {
this.pop();
sum=0;
for(int i=0; i<ptr; i++) {
sum+=stk[i];
}
}
}
}
public void pop() {
stk[--ptr]=0;
}
}
*/
import java.util.*;
class queue{
int [] q;
int [] a;
int answer=0, all=0;
int front, rear, capacity;
public queue(int max) {
this.capacity = max;
q = new int[capacity];
front=0;
rear=0;
}
public void enqueue(int x) {
if(rear == 0) {
q[rear++]=x;
answer ++;
}
else{
int sum=0;
for(int i=0; i<capacity; i++) {
sum += q[i];
}
if(capacity-sum>=x) {
q[rear++]=x;
answer ++;
}else{
q[rear++]=0;
this.enqueue(x);
answer ++;
}
if(rear == front) {
this.deque();
all += answer;
answer = 0;
}
}
}
public void deque() {
if(front==0) {
q[++front]=0;
}else {
if(front == capacity) {
front = 0;
}
}
}
}
public class Main{
public Main() {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
queue q = new queue(a); // 다리의 길이
int k= s.nextInt(); // 트럭 개수
int[] x = new int[k]; //트럭
for(int i=0; i<k; i++) {
x[i] = s.nextInt();
q.enqueue(x[i]);
}
}
public static void main(String[] args) {
new Main();
}
}