using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int ans = -1;
        int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int n = arr[0];
        int m = arr[1];
        string[] ansArr = new string[3];
        ansArr = ansArr.Select(a => a = "0").ToArray();
        for(int i = 0; i < m; i++)
        {
            string[] arrN = Console.ReadLine().Split(' ').ToArray();
            int keta = int.Parse(arrN[0]) - 1;
            if(keta + 1 > n)
            {
                Console.WriteLine(-1);
                return;
            }
            string c = arrN[1];
            if(ansArr[keta].Equals("0") || ansArr[keta].Equals(c))
            {
                ansArr[keta] = c;
            } else
            {
                Console.WriteLine(-1);
                return; 
            }
        }
        //ansArr = ansArr.Reverse().ToArray();
        if(n == 3)
        {
            if(!ansArr[0].Equals("0"))
            {
                ans = Henkan(ansArr,n);
            }
        } else if(n == 2)
        {
            if(ansArr[2].Equals("0") && !ansArr[1].Equals("0"))
            {
                ans = Henkan(ansArr, n);
            }
        }
        else
        {
            if (ansArr[2].Equals("0") && ansArr[1].Equals("0"))
            {
                ans = Henkan(ansArr, n);
            }
        }
        Console.WriteLine(ans);

    }
    static int Henkan(string[] arr,int n)
    {
        string hen = "";
        for(int i = 3-n; i <  3; i++)
        {
            hen += arr[i];
        }
        return int.Parse(hen);
    }

}



