using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInts();
            var N = NM[0];
            var M = NM[1];
            int[] array = { 0, 0, 0 };
            for (int i = 0; i < M; i++)
            {
                var sc = ReadInts();
                var s = sc[0];
                var c = sc[1];
                if (array[s - 1] != 0)
                {
                    if (array[s - 1] != c)
                    {

                        WriteLine(-1);
                        return;
                    }
                }
                array[s - 1] = c;
            }
            var ans = "";
            foreach (var item in array)
            {
                ans += item.ToString();
            }
            if (ans[0] == '0')
            {
                WriteLine(-1);
            }
            else
            {
                WriteLine(ans);
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}
