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

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = nm[0];
            var m = nm[1];

            var number = new int[n];
            var visited = new bool[n];

            for(int i = 0; i < m; i++)
            {
                var sc = Console.ReadLine().Split();
                var s = int.Parse(sc[0]);
                var c = int.Parse(sc[1]);

                if (visited[s - 1] && number[s - 1] != c)
                {
                    Console.WriteLine(-1);
                    return;
                }
                else if(n > 1 && s == 1 && c == 0)
                {
                    Console.WriteLine(-1);
                    return;
                }
                else
                {
                    visited[s - 1] = true;
                    number[s - 1] = c;
                }
            }

            int ans = 0;
            if(number[0] == 0)
            {
                number[0] = 1;
            }
            for(int i = 0; i < n; i++)
            {
                ans += number[i] * (int)Math.Pow(10, n - i - 1);
            }
            Console.WriteLine(ans);
        }
    }
}
