using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace ConsoleApp
{
    class Program
    {

        static void Main(string[] args)
        {
            var ar = ReadLine().Split().Select(int.Parse).ToArray();
            var n = ar[0];
            var m = ar[1];

            var s = new int[m];
            var c = new int[m];

            var res = new int[n];
            for (int i = 0; i < n;i++)res[i] = -1;

            for (int i = 0; i < m;i++)
            {
                ar = ReadLine().Split().Select(int.Parse).ToArray();
                s[i] = ar[0];
                c[i] = ar[1];

                if (res[s[i]-1] == -1)
                {
                    if (s[i] == 1 && c[i] == 0) { WriteLine("-1"); return; }
                    res[s[i]-1] = c[i];
                }
                else
                if (res[s[i]-1] != c[i])
                {
                    //矛盾
                    WriteLine("-1");
                    return;
                }
            }
            //最初の桁が指定がないときは必ず１
            if(res[0] == -1)res[0] = 1;

            for (int i = 1; i < n;i++)
            {
                if(res[i] == -1)res[i] = 0;
            }
            string str = "";
            for (int i = 0; i < n;i++) str = str + res[i];

            WriteLine(str);
        }   
        
       

    }

}
