using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC157
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            var s123 = new int[3] { -1, -1, -1 };
            for (int i = 0; i < s[1]; i++)
            {
                int[] sc = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
                if (s123[sc[0] - 1] == -1)
                {
                    s123[sc[0] - 1] = sc[1];
                }
                else
                {
                    if (s123[sc[0] - 1] != sc[1])
                    {
                        WriteLine(-1);
                        return;
                    }
                }
            }
            if (s[0] == 1)
            {
                if (s123[0] > 0 || s123[1] > 0)
                {
                    WriteLine(-1);
                    return;
                }
                else
                {
                    WriteLine(Max(s123[2], 0));
                    return;
                }
            }
            else if (s[0] == 2)
            {
                if (s123[0] > 0 || s123[1] == 0)
                {
                    WriteLine(-1);
                    return;
                }
                else
                {
                    Write(Max(s123[1], 1));
                    WriteLine(Max(s123[2], 0));
                }
            }
            else
            {
                if (s123[0] == 0)
                {
                    WriteLine(-1);
                    return;
                }else{
                    Write(Max(s123[0],1));
                    Write(Max(s123[1],0));
                    WriteLine(Max(s123[2],0));
                }

            }
        }
    }
}
