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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Guess The Number
            Console.WriteLine(CreateNumber());
        }

        static int CreateNumber()
        {
            var line = ReadLine();
            int N = line[0];
            int M = line[1];

            var number = new SortedDictionary<int, int>();

            for (int i = 0; i < M; i++)
            {
                line = ReadLine();
                int s = line[0];
                int c = line[1];

                if (N > 1 && s == 1 && c == 0)
                {
                    return -1;
                }

                if (number.ContainsKey(s))
                {
                    if (number[s] != c)
                    {
                        return -1;
                    }
                }
                else
                {
                    number.Add(s, c);
                }                
            }

            for(int i = 1; i <= N; i++)
            {
                if (!number.ContainsKey(i))
                {
                    if (i == 1)
                    {
                        number.Add(i, 1);
                    }
                    else
                    {
                        number.Add(i, 0);
                    }
                }
            }

            string ans = "";

            foreach(var n in number.Values)
            {
                ans += n;
            }

            return int.Parse(ans);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}