
#include <iostream>
#include <cmath>
using namespace std;
#define int unsigned long long
const int N = 1e5 + 10;
int n,m,t[N],ans,sum;
signed main()
{
ios::sync_with_stdio(0);
cin >> n >> m;
for(int i = 1;i <= m;i ++)
{
int x;
cin >> x;
sum += x;
t[(int)log2(x)] ++;
}
if (sum < n)
{
cout << -1 << endl;
return 0;
}
for(int i = 0;(1 << i) <= n;i ++)
{
if (!t[i] && (n & (1 << i)))
for(int j = i + 1;(1 << j) <= n;j ++)
if (t[j])
{
for(int k = j - 1;k >= i;k --)
ans ++,t[k + 1] --,t[k] += 2;
break;
}
if (n & (1 << i)) t[i] --;
t[i + 1] += t[i] / 2;
}
cout << ans << endl;
return 0;
}