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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var M = input[1];
            var num = Enumerable.Repeat<int>(-1, N).ToArray();
            for (int i = 0; i < M; i++)
            {
                input = ReadArrayInt();
                var s = input[0] - 1;
                var c = input[1];
                if (s == 0 && c == 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                else if (num[s] == -1) num[s] = c;
                else if (num[s] != c)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            if (N == 1 && num[0] == -1)
            {
                num[0] = 0;
            }
            else
            {
                if (num[0] == -1) num[0] = 1;
                for (int i = 1; i < N; i++)
                {
                    if (num[i] == -1) num[i] = 0;
                }
            }

            Console.WriteLine(string.Join("", num));
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}