#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,m;
    cin>>n>>m;
    vector <int> c;
    vector <int> d;
    int h,g;
    int h1,g1;
    if (n==1)
    {
        cin>>h>>g;
        int minimum=0;
        int maksimum=0;
        vector <int> rez;
        for (int i=0;i<m;i++)
        {
            cin>>h1>>g1;
            minimum=minimum+h1;
            maksimum=maksimum+g1;
            c.push_back(h1);
            d.push_back(g1);
            rez.push_back(h1);
        }
        if (minimum>=h)
        {
            int zbir=0;
            if (maksimum<g)
            {
                cout<<maksimum<<endl;
                int br=0;
                for (int i=0;i<m;i++)
                {
                    if (d[i]!=0)
                        br++;
                }
                cout<<br<<endl;
                for (int i=0;i<m;i++)
                {
                    cout<<d[i]<<" ";
                }
            }
            else
            {
                for (int i=0;i<m;i++)
                {
                    zbir=zbir+d[i];
                    if (zbir<g)
                    {
                        rez[i]=d[i];
                    }
                    if (zbir>g)
                    {
                        rez[i]=g-(zbir-d[i]);
                        break;
                    }
                }
                int br=0;
                for (int i=0;i<m;i++)
                {
                    if (rez[i]!=0)
                        br++;
                }
                cout<<g<<endl;
                cout<<br<<endl;
                for (int i=0;i<m;i++)
                {
                    cout<<rez[i]<<" ";
                }
            }
        }
        else
        {
            cout<<-1;
        }
    }
}