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

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = l[0], M = l[1];

        var dict = new Dictionary<int, int>();
        for (var i = 0; i < M; i++)
        {
            var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (t[0] == 1 && t[1] == 0)
            {
                if (N != 1)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }

            if (dict.ContainsKey(t[0]))
            {
                if (dict[t[0]] != t[1])
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
            else
                dict[t[0]] = t[1];
        }

        var one = dict.ContainsKey(1) ? dict[1] : 1;
        var two = dict.ContainsKey(2) ? dict[2] : 0;
        var three = dict.ContainsKey(3) ? dict[3] : 0;

        var ans = one.ToString();
        if (N >= 2) ans += two.ToString();
        if (N >= 3) ans += three.ToString();

        Console.WriteLine(ans);
    }
}

public class Util
{
}
