using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {
            string[] buf = Console.ReadLine().Split(' ');
            int digit = int.Parse(buf[0]);
            int max = int.Parse(buf[1]);

            List<int> testcaseS = new List<int>();
            List<int> testcaseM = new List<int>();

            for (int i=0; i < max; i++) {
                buf = Console.ReadLine().Split(' ');
                testcaseS.Add(int.Parse(buf[0]));
                testcaseM.Add(int.Parse(buf[1]));
            }

            int startRange = 0;
            int endRange=0;

            if(digit == 1) {
                startRange = 0;
                endRange = 10;
            }else if (digit == 2) {
                startRange = 10;
                endRange = 100;
            }else if(digit == 3) {
                startRange = 100;
                endRange = 1000;
            }

            bool checkF;

            for(int i=startRange; i < endRange; i++) {
                checkF = false;
                List<char> target = new List<char>(i.ToString().ToCharArray());

                for (int j = 0; j < max; j++) {
                    if (int.Parse(target[testcaseS[j]-1].ToString()) == testcaseM[j]) {
                        checkF = true;
                    } else {
                        checkF = false;
                        break;
                    }
                }
                if (checkF) {
                    Console.WriteLine(i);
                    return;
                }
            }

            Console.WriteLine(-1);


        }

    }

}
