using System.Linq;

namespace AtCoderCS
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    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]);
            }

            string ans;
            if (constraints.All(x => x.Value.Distinct().Count() <= 1))
            {
                var sb = new StringBuilder();
                for(var i = 1; i <= M; i++)
                {
                    var xx = constraints[i];
                    if (i == 1 && xx.Count == 0)
                    {
                        sb.Append(1);
                    }
                    else if (xx.Count == 0)
                    {
                        sb.Append("0");
                    }
                    else
                    {
                        sb.Append(xx[0]);
                    }
                }

                ans = sb.ToString();
                if (ans.Length > 1 && ans.ToCharArray().TakeWhile(cc => cc == '0').Any())
                {
                    ans = "-1";
                }
            }
            else
            {
                ans = "-1";
            }
            WriteLine(ans);
        }

        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
}