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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInts();
            int[] list = { -1, -1, -1 };
            for (int i = 0; i < NM[1]; i++)
            {
                var sc = ReadInts();
                if (list[sc[0] - 1] != -1)
                {
                    if(list[sc[0] - 1] != sc[1])
                    {
                        WriteLine("-1");
                        return;
                    }
                }
                else
                {
                    list[sc[0] - 1] = sc[1];
                }
            }
            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] == -1)
                {
                    list[i] = 0;
                }
            }
            var a = int.Parse(list[0] +""+ list[1] +""+ list[2]);
            if (a == 0)
            {
                WriteLine("-1");
                return;
            }
            WriteLine(a);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}
