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

class prog
{
    public static void Main(string[] args)
    {
        string[] in1 = Console.ReadLine().Split(' ');
        int N = int.Parse(in1[0]);
        int M = int.Parse(in1[1]);

        int[] Ss = new int[M];
        int[] Cs = new int[M];

        bool Out = false;
        int output = 0;
        int[] changed = new int[N];
        for (int i = 0; i < N; i++) { changed[i] = -1; }

        for (int i = 0; i < M; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            Ss[i] = int.Parse(input[0]);
            Cs[i] = int.Parse(input[1]);

            if (Ss[i] == 1 && Cs[i] == 0)
            {
                Out = true;
            }
        }

        for (int i = 0; i < M; i++)
        {
            if (changed[Ss[i] - 1] >= 0 && changed[Ss[i] - 1] != Cs[i]) { Out = true; break; }
            else if (changed[Ss[i] - 1] >= 0) break;
            else if (Ss[i] == 1)
            {
                output = (int)(Cs[i] * Math.Pow(10, N - 1) + output);
                changed[Ss[i] - 1] = Cs[i];
            }
            else if (Ss[i] == 2)
            {
                output = (int)(Cs[i] * Math.Pow(10, N - 2) + output);
                changed[Ss[i] - 1] = Cs[i];
            }
            else if (Ss[i] == 3)
            {
                output = (int)(Cs[i] * Math.Pow(10, N - 3) + output);
                changed[Ss[i] - 1] = Cs[i];
            }
        }

        for(int i = 0;i < N;i++)
        {
            if(changed[i] < 0)
            {
                if (i == 0) output = output + (int)(1 * Math.Pow(10, N - 1));
            }
        }

        if (!Out) Console.WriteLine(output);
        else Console.WriteLine("-1");
    }
}