using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
   
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
   

    public static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        var input = Reads();
        var n = input[0];
        var m = input[1];
        var s = new long[m];
        var c = new long[m];
        var d = new Dictionary<long, long>();
        bool f = false;
         for(int i = 0; i < m; i++)
        {
            input = Reads();
            if ((n == 2||n==3) && input[0] == 1 && input[1] == 0)
                f = true;
            else if (!d.ContainsKey(input[0]))
                d.Add(input[0], input[1]);
            else
            {
                if (d[input[0]] != input[1])
                    f = true;               
            }
        }
        long answer = 0;
        foreach(KeyValuePair<long,long> item in d)
        {
            answer += item.Value * (long)Math.Pow(10, n-item.Key);
        }
        if (f)
            Console.WriteLine(-1);
        else
        {
            Console.WriteLine(answer);
        }     
       
        Console.Out.Flush();

    }
}