using System;
using System.Linq;

public class AtCoder_157_C
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int n = line1[0];
        int m = line1[1];

        int[] ans = new int[n];
        for (int i = 0; i < n; i++)
        {
            ans[i] = -1;
        }

        bool err = false;

        for (int i = 0; i < m; i++)
        {
            int[] line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int s = line[0] - 1;
            int c = line[1];
            if (ans[s] != -1 && ans[s] != c)
            {
                err = true;
            }
            ans[s] = c;
        }

        if (ans[0] == 0 && n > 1)
        {
            err = true;
        }

        if (err)
        {
            Console.WriteLine(-1);
            return;
        }

        int val = 0;
        int keta = 1;
        for (int i = n - 1; i >= 0; i--)
        {
            if (ans[i] == -1)
            {
                if (i == 0)
                {
                    val += keta;
                }
            }
            else
            {
                val += ans[i] * keta;
            }
            keta *= 10;
        }

        Console.WriteLine(val);
    }
}
