#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int w,n;

bool ok1(vi& sm,int st,int cri)
{
    int diff = sm[st+cri]-sm[st]+cri-1;
    return diff <= w;
}

bool ok2(vi& sm,int st,int cri,int d)
{
    int diff = sm[st+cri]-sm[st]+(cri-1)*d;
    return w <= diff;
}

bool possible(vi& sm,int d)
{
    vi dp(n+5,0);
    dp[0] += 1;
    dp[1] += -1;
    int nw = 0;
    int last;
    rep(i,n){
        nw += dp[i];
        if(nw){
            last = i;
            int lb,rb;
            if(ok1(sm,i,n-i)){
                lb = n;
            }else{
                int l = 2,r = n-i;
                while(r-l>1){
                    int mid = (l+r)/2;
                    if(ok1(sm,i,mid)){
                        l = mid;
                    }else{
                        r = mid;
                    }
                }
                lb = i+l;
            }
            if(ok2(sm,i,2,d)){
                rb = i+2;
            }else{
                int l = 2,r = n-i;
                while(r-l>1){
                    int mid = (l+r)/2;
                    if(ok2(sm,i,mid,d)){
                        r = mid;
                    }else{
                        l = mid;
                    }
                }
                rb = i+r;
            }
            if(rb <= lb){
                dp[rb] += 1;
                dp[lb+1] -= 1;
            }
        }
    }
    if(nw+dp[n]){
        return true;
    }
    if(sm[n]-sm[last]+(n-last-1) <= w){
        return true;
    }else{
        return false;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        cin >> w >> n;
        if(w + n == 0){
            break;
        }
        vi vec(n),sm(n+1);
        rep(i,n){
            cin >> vec[i];
        }
        sm[0] = 0;
        rep(i,n){
            sm[i+1] = sm[i] + vec[i];
        }
        // possible(sm,1);
        int l = 0,r = w;
        while(r-l>1){
            int mid = (l+r)/2;
            if(possible(sm,mid)){
                r = mid;
            }else{
                l = mid;
            }
        }
        cout << r << "\n";
    }
    return 0;
}

Measured memory_bytes: 3480