#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int MaxN=100005;
typedef long long LL;
LL e[20];
LL x,n;
struct box {
    LL k,q,s;
    int b;
    bool operator < (const box &a)const { return s<a.s; }
} a[MaxN];

vector <box> v;

int cmpk(box a,box b){ return a.k<b.k; }
int cmpb(box a,box b){ return a.b<b.b; }

void init(){
    scanf("%I64d%I64d",&x,&n);
    for (int i=0; i<n; i++){
        scanf("%I64d%I64d",&a[i].k,&a[i].q);
        a[i].s=e[a[i].k]*a[i].q;
        a[i].b=i+1;
    }
}

void writeit(){
    sort(v.begin(),v.end(),cmpb);
    printf("%d\n",int(v.size()));
    for (int i=0; i<v.size()-1; i++) printf("%d ",v[i].b);
    printf("%d\n",v.back().b);
}

int gao(){
    priority_queue <box> q;
    LL res=0,now=0,l=0,i,j;
    for (i=1; i<=19; i++){
        if (x<=0) return 1;
        now=(x%10)*e[i-1];
        x/=10;
        for (j=l; j<n; j++)
            if (a[j].k<i) q.push(a[j]); else break;
        l=j;

        now=now-res;
        while (!q.empty() && now>0){
            now-=q.top().s;
            v.push_back(q.top());
            q.pop();
        }
        if (now>0) return 0;
        res=abs(now);
    }
    return 1;
}

int main(){
    e[0]=1;
    for (int i=1; i<=18; i++) e[i]=e[i-1]*10;
    freopen("exact.in","r",stdin);
    freopen("exact.out","w",stdout);
    init();
    sort(a,a+n,cmpk);
    if (!gao()) puts("-1"); else writeit();
    return 0;
}