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

class Program
{
    static void Main(string[] args)
    {
        var line1 = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
        var N = line1[0];
        var M = line1[1];

        // key=桁数、val:数値
        Dictionary<int, int> ranks = new Dictionary<int, int>();

        for (int i = 0; i < M; i++)
        {
            var line = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToList();
            var s = N + 1 - line[0];
            var c = line[1];

            if (s == N && c == 0)
            {
                Console.WriteLine("-1");
                return;
            }

            if (!ranks.ContainsKey(s))
            {
                ranks.Add(s, c);
            }
            else
            {
                if (ranks[s] != c)
                {
                    Console.WriteLine("-1");
                    return;
                }
            }
        }

        var min = (long) Math.Pow(10, N - 1);

        long answer = 0;
        foreach (var kvp in ranks)
        {
            var val = (long) Math.Pow(10, kvp.Key - 1) * kvp.Value;
            answer += val;
        }

        if (answer < min)
        {
            answer += min;
        }

        Console.WriteLine(answer.ToString());
    }
}