
using System.Collections.Generic;

using System;
using System.Linq;
class Program
{

    static void Main(string[] args)
    {

        long[] inp = null;
        inp = Console.ReadLine().Split(' ').Select(k => long.Parse(k)).ToArray();
        long n, m;
        n = inp[0]; m = inp[1];


        var ketas = new List<long>();
        var nums = new List<long>();

        for (int i = 0; i < m; i++)
        {
            inp = Console.ReadLine().Split(' ').Select(k => long.Parse(k)).ToArray();

            ketas.Add(inp[0]);
            nums.Add(inp[1]);
        }


        var str = new List<string>();
        for (int i = 0; i < n; i++)
        {
            str.Add("0");
        }

        bool failure = false;
        for (int i = 0; i < m; i++)
        {
            int k = (int)ketas[i] - 1;
            long tmp = long.Parse(str[k]);

            if (tmp > 0 && nums[i] != tmp)
            {
                failure = true;
            }
            else if (tmp == 0)
            {
                str[k] = nums[i].ToString();
            }
        }

        if (str[0] == "0") failure = true;

        long ans = long.Parse(string.Concat(str));
        if (failure) ans = -1;

        if (n == 1 && m == 1 && nums[0] == 0) ans = 0;

        Console.WriteLine(ans);

    }
}
