using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            var N = items[0];
            var M = items[1];

            var table = new Dictionary<int, int>();
            foreach (var i in Enumerable.Range(1, N))
            {
                if (i == 1)
                {
                    table[i] = N == 1 ? 0 : 1;
                }
                else
                {
                    table[i] = 0;
                }
            }

            foreach (var i in Enumerable.Range(0, M))
            {
                var items2 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
                var s = items2[0];
                var c = items2[1];
                if (table[s] == 0 || table[s] == c)
                {
                    table[s] = c;
                }
                else
                {
                    Console.WriteLine("-1");
                    return;
                }
            }

            var answer = int.Parse(string.Concat(Enumerable.Range(1, N).Select(i => table[i].ToString())));
            if (answer.ToString().Length != N)
            {
                Console.WriteLine("-1");
                return;
            }

            Console.WriteLine(answer);
        }
    }
}
