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];
        for(int i = 0; i < m; i++)
        {
            input = Reads();
            s[i] = input[0];
            c[i] = input[1];
        }
        bool g = false;
        long anwer = 0;
        var d = new long[n];
        for (int i = 0; i < (long)Math.Pow(10, n); i++)
        {              
                int count = 0;
            for (int j = 0; j < m; j++)
            {
                if (c[j] == i / (long)Math.Pow(10, n-s[j]) % 10)
                    count++;                       
            }
            if (count == m)
            {
                g = true;
                anwer = i;
                break;
            }
            
        }
        if (g)
            Console.WriteLine(anwer);
        else
            Console.WriteLine(-1) ;
           
       
        Console.Out.Flush();

    }
}

