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

public class Program
{
    public static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var dict = new Dictionary<int, int>();
        for (int i = 0; i < nm[1]; i++)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            if (!dict.ContainsKey(vals[0]))
            {
                dict.Add(vals[0], vals[1]);
            }
            else
            {
                if (dict[vals[0]] != vals[1])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            if (dict.ContainsKey(1) && dict[1] == 0)
            {
                Console.WriteLine(-1);
                return;
            }
        }
        var result = new int[nm[0]];
        for (int i = 0; i < nm[0]; i++)
        {
            if (dict.ContainsKey(i + 1))
            {
                result[i] = dict[i + 1];
            }
            else
            {
                result[i] = 0;
            }
        }
        if (result[0] == 0)
        {
            result[0]++;
        }
        Console.WriteLine(string.Join("", result));
    }
}