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

public class Hello
{
    public static void Main()
    {
        hoge();
    }

    public static void hoge()
    {
        var line = System.Console.ReadLine().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);

        int[] num = { 0, 0, 0 };

        Dictionary<int, int> deta = new Dictionary<int, int>();
        if (n == 1)
        {
            num[0] = 0;
            for (int i = 0; i < m; i++)
            {
                line = System.Console.ReadLine().Split(' ');
                var s = int.Parse(line[0]);
                var c = int.Parse(line[1]);

                if (deta.ContainsKey(s) && deta[s] != c)
                {
                    for(int j = i + 1; j < m; j++)
                    {
                        System.Console.ReadLine();
                    }
                    System.Console.WriteLine("-1");
                    return;
                }

                if (deta.ContainsKey(s) && deta[s] == c)
                {
                    continue;
                }

                if (s == 1)
                {
                    num[0] = c;
                }
                deta.Add(s, c);
            }
            System.Console.WriteLine(num[0]);
            return;
        }

        if (n == 2)
        {
            num[1] = 1;
            for (int i = 0; i < m; i++)
            {
                line = System.Console.ReadLine().Split(' ');
                var s = int.Parse(line[0]);
                var c = int.Parse(line[1]);

                if (deta.ContainsKey(s) && deta[s] != c)
                {
                    for (int j = i + 1; j < m; j++)
                    {
                        System.Console.ReadLine();
                    }
                    System.Console.WriteLine("-1");
                    return;
                }
                if (deta.ContainsKey(s) && deta[s] == c)
                {
                    continue;
                }

                if (s == 1)
                {
                    num[1] = c;
                }
                else
                {
                    num[0] = c;
                }
                deta.Add(s, c);
            }
            if (num[1] == 0)
            {
                System.Console.WriteLine("-1");
                return;
            }
            System.Console.WriteLine("" + num[1] + num[0]);
            return;
        }

        if (n == 3)
        {
            num[2] = 1;
            for (int i = 0; i < m; i++)
            {
                line = System.Console.ReadLine().Split(' ');
                var s = int.Parse(line[0]);
                var c = int.Parse(line[1]);

                if (deta.ContainsKey(s) && deta[s] != c)
                {
                    for (int j = i + 1; j < m; j++)
                    {
                        System.Console.ReadLine();
                    }
                    System.Console.WriteLine("-1");
                    return;
                }
                if (deta.ContainsKey(s) && deta[s] == c)
                {
                    continue;
                }

                if (s == 1)
                {
                    num[2] = c;
                }
                else if (s == 2)
                {
                    num[1] = c;
                }
                else
                {
                    num[0] = c;
                }
                deta.Add(s, c);
            }
            if (num[2] == 0)
            {
                System.Console.WriteLine("-1");
                return;
            }
            System.Console.WriteLine("" + num[2] + num[1] + num[0]);
            return;
        }
    }
}

Measured memory_bytes: 13152