using System;

namespace ABC157_C
{
    class Program
    {
        static int Main(string[] args)
        {
            var L1 = Console.ReadLine().Split(' ');
            var N = int.Parse(L1[0]);
            var M = int.Parse(L1[1]);
            var S = new int[5];
            var C = new int[5];

            for (int i = 0; i < M; i++)
            {
                var L2 = Console.ReadLine().Split(' ');
                S[i] = int.Parse(L2[0]) - 1;
                C[i] = int.Parse(L2[1]);
            }

            var X = new int[3];

            for (int i = 0; i < M; i++)
            {
                if (X[S[i]] == 0)
                {
                    X[S[i]] = C[i];
                }
                else if(X[S[i]] == C[i])
                {

                }
                else
                {
                    Console.WriteLine("-1");
                    return 0;
                }
            }

            var R = 0;
            if (N == 1) R = X[0];
            if (N == 2)
            {
                R = X[0] * 10 + X[1];
                if (R < 10) R = -1;
            }
            if (N == 3)
            {
                R = X[0] * 100 + X[1] * 10 + X[2];
                if (R < 100) R = -1;
            }

            Console.WriteLine($"{R}");
            return 0;
        }
    }
}
