# data[].attributes.attachment_link.readable_text
uses crt,math;
var a:array of longint;
function check(a:array of longint;k,s:longint):boolean;
var i,sum:longint;
begin
  i:=high(a);
  sum:=0;
  while k>0 do
  begin
    sum:=sum+a[i];
    dec(i);
    dec(k);
  end;
  check:=sum>=s;
end;
function solve(a:array of longint;n,s:longint):longint;
var l,r,m,ans,i:longint;
begin
  l:=1;  r:=n;  ans:=-1;
  while l<=r do
  begin
    m:=(l+r)div 2;
    if check(a,m,s) then
    begin
      r:=m-1;
      ans:=m;
    end
    else l:=m+1;
  end;
  for i:=0 to high(a) do
  if s mod a[i]=0 then ans:=min(ans,s div a[i]);
  solve:=ans;
end;
var s,n,i: Longint;
begin
  assign(input,'TINHTONG.INP');reset(input);
  assign(output,'TINHTONG.OUT');rewrite(output);
  readln(s,n);
  setlength(a,n);
  for i:=0 to n-1 do read(a[i]);
  write(solve(a,n,s));
end.

# data[].attributes.attachment_link.readable_text
#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen("TRATIEN.INP","r",stdin);
    freopen("TRATIEN.OUT","w",stdout);
    int n, m; cin>>n>>m;
    vector<int> a(n);
    for (int i=0;i<n;i++) cin>>a[i];
    int d=0;
    vector<int> soto(n);
    for (int i=n-1;i>=0;i--)
    {
      if (m/a[i]!=0)
      {
        soto[i]=m/a[i];
        d+=m/a[i];
        m-=m/a[i]*a[i];
        
      }
        else soto[i]=0;
    }
    cout<<d<<'\n';
    for (int i=0;i<n;i++) cout<<soto[i]<<" ";
    return 0;
}


# data[].attributes.attachment_link.readable_text
#include <bits/stdc++.h>
using namespace std;
bool cmp(string a, string b)
{
    if (a.length()<b.length())
    {
        int i=0;
        while (i+a.length()<=b.length())
        {
            string c=b.substr(i,a.length());
            //cout<<a<<" "<<c<<" "<<a<<" "<<b<<'\n';
            if (a>c) return true;
                else if (a<c) return false;
            i+=a.length();
        }
        cout<<" "<<i<<'\n';
        if (i<b.length())
            {
                string d=b.substr(i);
                return d<a.substr(0,d.length());
            }
        return a.length()<b.length();
    }
        else if (a.length()>b.length())
        {
            int i=0;
            while (i+b.length()<=a.length())
            {
                string c=a.substr(i,b.length());
                //cout<<c<<" "<<b<<" "<<a<<" "<<b<<'\n';
                if (c>b) return true;
                    else if (c<b) return false;
                i+=b.length();
            }
            //cout<<" "<<i<<'\n';
            if (i<a.length())
            {
                string d=a.substr(i);
                //cout<<"     "<<d<<" "<<b.substr(0,d.length())<<'\n';
                return d>b.substr(0,d.length());
            }
            return a.length()<b.length();
        }
    return a>b;
}
int main()
{
    freopen("GHEPSO.INP","r",stdin);
    freopen("GHEPSO.OUT","w",stdout);
    int n; cin>>n;
    string a[n];
    for (int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,cmp);
    for (int i=0;i<n;i++) cout<<a[i];
    return 0;
}

# data[].attributes.body
chấm lại giùm em đi thầy

# data[].attributes.body
5 2 6 9 7 5 8 6 9 8

2 5 7 4 5 3 4 2 3 4

5 9 7 5 6 7 9 8 2 3

1 2 1 3 1 3 6 4 3 4

5 9 6 8 6 5 3 5 6 7

2 6 8 9 5 6 4 5 6 8

9 8 2 4 5 7 5 6 7 5

5 6 8 9 7 5 9 4 5 4

2 5 8 6 9 7 5 8 6 8

5 4 1 2 3 4 5 7 6 8

# data[].attributes.body
var a:array[1..100,1..100] of longint;
    m,n,i,j,t:longint;
    f,g:text;
function kt(i,j:longint):boolean;
var k:longint;
begin
   for k:=1 to i do
     if a[k,j]=0 then break;
   if k=i then exit(false);
   for k:=1 to j do
     if a[i,k]=0 then break;
   if k=j then exit(false);
   for k:=m downto i do
     if a[k,j]=0 then break;
   if k=i then exit(false);
   for k:=n downto j do
     if a[i,k]=0 then break;
   if k=j then exit(false);
   exit(true);
end;
begin
    assign(f,'vung.inp');reset(f);
    assign(g,'vung.out');rewrite(g);
    readln(f,m,n);
    for i:=1 to m do
      begin
        for j:=1 to n do
          read(f,a[i,j]);
        readln(f);
      end;
    t:=0;
    for i:=2 to m-1 do
      for j:=2 to n-1 do
        if kt(i,j) then t:=t+a[i,j];
    write(g,t);
    close(f);close(g);
end.

# data[].attributes.body
73

7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7 4 7

# data[].attributes.body
52

2 3 6 3 9 1 3 4 2 7 1 8 9 9 1 9 6 2 3 6 3 9 1 3 4 2 7 1 8 9 9 1 9 6 2 3 6 3 9 1 3 4 2 7 1 8 9 9 1 9 6 2