namespace AtCoderCS
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Linq;
    using static System.Console;
    using static System.Math;

    class Program
    {
        void Solve()
        {
            var N = IN.Int;
            var M = IN.Int;
            var s = new int[M];
            var c = new int[M];
            for (var i = 0; i < M; i++)
            {
                s[i] = IN.Int;
                c[i] = IN.Int;
            }

            var constraints = new Dictionary<int,List<int>>();
            for (var i = 1; i <= N; i++)
            {
                constraints[i] = new List<int>();
            }

            for (var i = 0; i < M; i++)
            {
                constraints[s[i]].Add(c[i]);
            }

            if (N == 1)
            {
                var isValid =
                    constraints.All(x => x.Value.Distinct().Count() <= 1);
                if (!isValid)
                {
                    WriteLine(-1);
                }
                else
                {
                    WriteLine(constraints[1].Any()? constraints[1][0]: 0);   
                }
            }
            else
            {

                var isValid =
                    constraints.All(x => x.Value.Distinct().Count() <= 1)
                    && !constraints[1].Contains(0);

                if (!isValid)
                {
                    WriteLine(-1);
                }
                else
                {
                    var sb = new StringBuilder();
                    for (var i = 1; i <= N; i++)
                    {
                        if (i == 1)
                        {
                            sb.Append(!constraints[1].Any() ? 1 : constraints[1][0]);
                        }
                        else
                        {
                            sb.Append(!constraints[i].Any() ? 0 : constraints[i][0]);
                        }
                    }

                    WriteLine(sb.ToString());
                }
            }
        }

        private SimpleInput IN = new SimpleInput();
        private SimpleOutput OUT = new SimpleOutput();

        void Stream()
        {
            Solve();
            OUT.Flush();
        }

        static void Main(string[] args)
            => new Program().Stream();
    }

    #region IO

    class SimpleInput
    {
        private string[] _nextBuffer;
        private int _bufferCnt;
        private readonly char[] _cs = new char[] {' ', '"', ','};

        public SimpleInput()
        {
            _nextBuffer = new string[0];
            _bufferCnt = 0;
        }

        string Next()
        {
            if (_bufferCnt < _nextBuffer.Length) return _nextBuffer[_bufferCnt++];
            var st = ReadLine();
            while (st == string.Empty) st = ReadLine();
            if (st != null) _nextBuffer = st.Split(_cs, StringSplitOptions.RemoveEmptyEntries);
            _bufferCnt = 0;
            return _nextBuffer[_bufferCnt++];
        }

        public string String => Next();
        public char Char => char.Parse(String);
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
    }

    class SimpleOutput
    {
        private readonly StreamWriter _sw = new StreamWriter(OpenStandardOutput())
        {
#if DEBUG
            AutoFlush = true
#else
            AutoFlush = false
#endif
        };

        public SimpleOutput()
        {
            SetOut(_sw);
        }

        public void Flush() => Out.Flush();
    }

    #endregion
}

Measured memory_bytes: 13268