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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split(' ');
            var N = r[0].ToInt();
            var M = r[1].ToInt();
            var max = Math.Pow(10, N).ToInt();
            var min = Math.Pow(10, N - 1).ToInt();
            var l = new Dictionary<int, int>();
            var ans = 0;
            for (int i = 0; i < M; i++)
            {
                var sc = Console.ReadLine().Split(' ');
                var s = sc[0].ToInt();
                var c = sc[1].ToInt();
                if (l.ContainsKey(s))
                {
                    if (l[s] == c)
                    {
                        continue;
                    }
                    else
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
                l.Add(s, c);
                ans += Math.Pow(10, N - s).ToInt() * c;
                if (s == 1 && ans < min)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            if (ans >= max)
            {
                Console.WriteLine(-1);
                return;
            }
            if (ans < min)
            {
                ans += min;
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }

    public static class Extensions
    {
        public static int ToInt(this object str)
        {
            return int.Parse(str.ToString());
        }

        public static decimal ToDecimal(this object str)
        {
            return decimal.Parse(str.ToString());
        }
    }
}
