using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();

            string[] strs = line.Split(' ');

            int N = int.Parse(strs[0]);
            int M = int.Parse(strs[1]);
            List<Tuple<int, int>> list = new List<Tuple<int, int>>();
            int result = -1;
            for(int i = 0; i < M; i++)
            {
                line = Console.ReadLine();
                strs = line.Split(' ');
                list.Add(new Tuple<int,int>(int.Parse(strs[0]),int.Parse(strs[1])));
            }
            int MIN = 0;
            int MAX = 0;
            if (N == 1)
            {
                MAX = 9;
            }
            else if (N ==2)
            {
                MIN = 10;
                MAX = 99;
            }
            else
            {
                MIN = 100;
                MAX = 999;
            }
            for(int i = MIN; i<= MAX; i++)
            {
                var OK = true;
                foreach(var data in list)
                {
                    if (N == 3)
                    {
                        if (data.Item1 == 1)
                        {
                            if (i / 100 != data.Item2)
                            {
                                OK = false;
                                break;
                            }
                        }
                        else if (data.Item1 == 2)
                        {
                            if (i / 10 % 10 != data.Item2)
                            {
                                OK = false;
                                break;
                            }
                        }
                        else
                        {
                            if (i % 10 != data.Item2)
                            {
                                OK = false;
                                break;
                            }
                        }
                    }
                    else if (N == 2)
                    {
                        if (data.Item1 == 1)
                        {
                            if (i / 10 % 10 != data.Item2)
                            {
                                OK = false;
                                break;
                            }
                        }
                        else
                        {
                            if (i % 10 != data.Item2)
                            {
                                OK = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (i % 10 != data.Item2)
                        {
                            OK = false;
                            break;
                        }
                    }
                }
                if (OK)
                {
                    result = i;
                    break;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13268