using System;
using System.Linq;
using System.Security.Cryptography;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var s = new int[M];
        var c = new char[M];
        for (int i = 0; i < M; i++)
        {
            var sc = ReadLine().Split(' ').ToArray();
            (s[i], c[i]) = (int.Parse(sc[0]) - 1, sc[1][0]);
        }

        var cStr = Enumerable.Repeat('*', N).ToArray();
        var impossible = false;

        for (int i = 0; i < M; i++)
        {
            if (cStr[s[i]] == '*')
            {
                cStr[s[i]] = c[i];
            }
            else if (cStr[s[i]] == c[i])
            { }
            else
            {
                impossible = true;
                break;
            }
        }

        for (int i = 0; i < N; i++)
        {
            if (cStr[i] == '*')
            {
                cStr[i] = (i == 0) ? '1' : '0';
            }
        }

        if (impossible)
            cStr = "-1".ToCharArray();

        var str = new string(cStr);
        var n = int.Parse(str);
        var digit = n.ToString().Length;

        if (digit != N)
            n = -1;

        WriteLine(n);
    }
}
