using System;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);
            string[] str1 = new string[2];
            int[] number = new int[2 * M];

            for(int i = 0; i <= M - 1; i++)
            {
                
                str1 = Console.ReadLine().Split(' ');
                number[2*i] = int.Parse(str1[0]);
                number[2 * i + 1] = int.Parse(str1[1]);
            }
            bool check = true;

            //for (int i = 0; i <= M - 1; i++)
            //{
            //    Console.Write(number[i * 2]);
            //    Console.WriteLine(number[i * 2 + 1]);
            //}

            for (int i = 0; i <= M - 1; i++)
            {
                for(int j = i+1; j <= M - 1; j++)
                {
                    if (number[i * 2] == number[j * 2])
                    {
                        if (number[(i * 2) + 1] != number[(j * 2) + 1])
                        {
                            check = false;
                        }
                        else if(number[(i * 2) + 1] == number[(j * 2) + 1]) number[(j * 2)+1] = 0;
                    }
                }
            }

            //for(int i = 0; i <= M - 1; i++)
            //{
            //    Console.Write(number[i*2]);
            //    Console.WriteLine(number[i * 2+1]);
            //}
            
            if (check)
            {
                double answer = 0;
                for (int i = 0; i <= M - 1; i++)
                {
                    answer += number[i * 2 + 1] * (Math.Pow(10, N - number[i * 2]));
                }
                if (System.Math.Log10(answer) >= N ) Console.WriteLine((int)answer);
                else Console.WriteLine(-1);
            }
            else Console.WriteLine(-1);
            //string[] str = Console.ReadLine().Split(' ');
            //string s = Console.ReadLine();

            //string[] str1 = Console.ReadLine().Split(' ');
            //int[] number = str.Select(int.Parse).ToArray();



        }
    }
}