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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nm[0];
        var m = nm[1];
        var digits = new SortedSet<int>[n];
        for (int i = 0; i < digits.Length; ++i)
        {
            digits[i] = new SortedSet<int>();
        }
        for (int i = 0; i < m; ++i)
        {
            var sc = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            
            digits[sc[0] - 1].Add(sc[1]);
        }

        if (digits[0].LastOrDefault() == 0)
        {
            Console.WriteLine("-1");
            return;
        }
        else if (digits.Length == 1 && digits[0].LastOrDefault() == 0)
        {
            Console.WriteLine("0");
            return;
        }

        var s = new string(digits.Select(x => (char)(x.FirstOrDefault() + '0')).ToArray());
        Console.WriteLine(s);
    }
}
