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

internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.C
{
    public class Program
    {
        public static long N { get; private set; }
        public static long M { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            N = inputs[0];
            M = inputs[1];

            var sc = new List<SC>();
            for (int i = 0; i < M; i++)
            {
                inputs = CR.GetLongs();
                sc.Add(new SC
                {
                    S = inputs[0],
                    C = inputs[1],
                });
            }

            // 最大桁数が0ならNG
            if (N != 1 // 1桁のときは最大桁が0でもよい
                && sc.Any(x => x.S == 1 && x.C == 0)) return "-1";

            // 制約が破綻しているならNG
            foreach (var item in sc)
            {
                if (sc.Any(x => x.S == item.S && x.C != item.C)) return "-1";
            }

            var result = "";
            for (int i = 1; i <= N; i++)
            {
                var v = sc.FirstOrDefault(x => x.S == i);
                if (v != null)
                {
                    result += v.C;
                }
                else
                {
                    result += 0;
                }
            }
            return result;
        }
    }

    internal class SC
    {
        public long S { get; internal set; }
        public long C { get; internal set; }
    }
}
