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

namespace ABC157
{
    class Program
    {
        static void Main(string[] args)
        {
            c();
        }

        public static void c()
        {
            bool flg = true;
            int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nm[0], m = nm[1];
            int[] ans1 = new int[n];
            bool[] flg1 = new bool[n];
            bool flg3 = false;
            for(int i = 0; i < n; i++)
            { flg1[i] = true; }
            if(n == 1 && m == 0)
            {
                Console.WriteLine(0);
                return;
            }
            for(int i = 0; i < m; i++)
            {
                int[] sc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int s = sc[0], c = sc[1];
                if(n == 1 && s == 1 && c == 0)
                {
                    Console.WriteLine(0);
                    return;
                }
                if(flg1[s - 1] == false && ans1[s - 1] != c)
                {
                    flg = false;
                    break;
                }
                ans1[s - 1] = c;
                if(ans1[s - 1] == c)
                { flg3 = true; }
                flg1[s - 1] = false;
            }
            if(n > 1 && ans1[0] == 0 || flg3 == false)
            {
                flg = false;
            }
            if(flg)
            {
                foreach (var x in ans1)
                {
                    Console.Write(x);
                }
                Console.WriteLine();
            }
            else
            { Console.WriteLine(-1); }
        }
    }
}
