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("X");
        }

        //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]);

            var ch = (char)('0' + c);

            if (s == 1 && c == 0) return -1;
            if (str[s - 1] != 'X' && str[s - 1] != ch) return -1;

            str[s - 1] = ch;
        }

        if (str[0] == 'X' && n !=1 ) str[0] = '1';

        var v = int.Parse(str.Replace('X', '0').ToString());
        return v;
    }
}
