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

class Program
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        int[] s = new int[M];
        int[] c = new int[M];
        for(int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split();
            s[i] = int.Parse(input[0]);
            c[i] = int.Parse(input[1]);
        }
        int start = (int)Math.Pow(10, N - 1);
        int goal = 10;
        goal = Math.Max(start * 10, goal);
        int ans = 0;
        for (int i = start; i < goal; i++)
        {
            string temp = i.ToString();
            bool flag = true;
            for (int j = 0; j < M; j++)
            {
                if (temp[s[j] - 1].ToString() == c[j].ToString() && flag == true)
                {
                    flag = true;
                }
                else flag = false;
            }
            if (flag == true&&ans==0) { ans=i; }
        }
        if (ans==0) { ans = -1; }
        Console.WriteLine(ans);
    }
}