using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC157C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInt();
            int N = NM[0];
            int M = NM[1];

            int[] s = new int[M];
            string[] c = new string[M];
            for (int i = 0; i < M; i++)
            {
                var input = ReadInt();
                s[i] = input[0] - 1;
                c[i] = input[1].ToString();
            }

            int ans = Solve(N, M, s, c);

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static int Solve(int N, int M, int[] s, string[] c)
        {
            for (int i = (int)Math.Pow(10, N - 1); i < (int)Math.Pow(10, N); i++)
            {
                string str = i.ToString();

                for (int j = 0; j < M; j++)
                {
                    if (str.Length <= s[j]) break;
                    if (str[s[j]].ToString() != c[j]) break;

                    //終了条件
                    if (j == M - 1) return i;
                }
            }
            return -1;
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}
