using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    //static long mod = 1000000007;

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var n     = int.Parse(spl[0]);
        var m     = int.Parse(spl[1]);

        StringBuilder str = new StringBuilder();
        for(int i=0; i<n; i++) {
            str.Append("0");
        }

        Dictionary<int, int> hash = new Dictionary<int, int>();

        for(int i=0; i < m; i++) {
            spl   = input.ReadLine().Split(' ');
            var s = int.Parse(spl[0]);
            var c = int.Parse(spl[1]);

            if (s == 1 && c == 0) return -1;
            if (hash.ContainsKey(s) && hash[s] != c) return -1;

            if (!hash.ContainsKey(s)) hash.Add(s, c);

            str[s-1] = (char)('0' + c);
        }

        return int.Parse(str.ToString());
    }
}
