using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var nm = IO.ReadSplitInt;
            var s = new int[nm[1]];
            var c = new int[nm[1]];
            for (int i = 0; i < nm[1]; i++)
            {
                var t = IO.ReadSplitInt;
                s[i] = t[0];
                c[i] = t[1];
            }
            int min = 0;
            int max = 0;
            if (nm[0] == 1)
            {
                max = 9;
            }
            else if (nm[0] == 2)
            {
                min = 10;
                max = 99;
            }
            else
            {
                min = 100;
                max = 999;
            }
            int ans = -1;
            for (int i = min; i <= max; i++)
            {
                var f = true;
                for (int j = 0; j < nm[1]; j++)
                {
                    #region
                    if (nm[0] == 3)
                    {
                        if (s[j] == 1)
                        {
                            if (i / 100 != c[j])
                            {
                                f = false;
                                break;
                            }
                        }
                        else if (s[j] == 2)
                        {
                            if (i / 10 % 10 != c[j])
                            {
                                f = false;
                                break;
                            }
                        }
                        else
                        {
                            if (i % 10 != c[j])
                            {
                                f = false;
                                break;
                            }
                        }
                    }
                    else if (nm[0] == 2)
                    {
                        if (s[j] == 1)
                        {
                            if (i / 10 % 10 != c[j])
                            {
                                f = false;
                                break;
                            }
                        }
                        else
                        {
                            if (i % 10 != c[j])
                            {
                                f = false;
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (i != c[j])
                        {
                            f = false;
                            break;
                        }
                    }
                    #endregion

                    if (j == nm[1] - 1 && f == true)
                    {
                        ans = i;
                        break;
                    }
                }
                if (ans != -1) break;
            }
            WriteLine(ans);
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            // 割る数の定義
            private readonly static long M = 1000000007;

            // 足し算
            public static long Add(long a, long b) => (a * b) % M;
            // 引き算
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            // 掛け算
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public class Scanner
        {
            #region
            public string Str => Console.ReadLine().Trim();
            public int Int => int.Parse(Str);
            public long Long => long.Parse(Str);
            public double Double => double.Parse(Str);
            public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
            public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
            //public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
            //public int[] ArrInt1D(int n) => Create(n, () => Int);
            //public long[] ArrLong1D(int n) => Create(n, () => Long);
            //public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
            //public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
            private Queue<string> q = new Queue<string>();
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            // インライン化を推奨する
            public T Next<T>()
            {
                if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item);
                return (T)Convert.ChangeType(q.Dequeue(), typeof(T));
            }
            public void Make<T1>(out T1 v1) => v1 = Next<T1>();
            public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
            public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
            public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
            public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
            public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
#endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}