using System;

namespace AtC157
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NM = Console.ReadLine().Split(' ');
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);
            int[] s = new int[M];
            int[] c = new int[M];

            bool[] a = new bool[N+1];
            int[] b = new int[N+1];
            bool error = false;
            for (int i = 0; i < M; i++)
            {
                string[] sc = Console.ReadLine().Split(' ');
                s[i] = int.Parse(sc[0]);
                c[i] = int.Parse(sc[1]);

                if (a[s[i]])
                {
                    if (b[s[i]] != c[i]) error = true;
                    
                }
                else
                {
                    a[s[i]] = true;
                    b[s[i]] = c[i];
                }
                if (N > 1 && s[i] == 1 && c[i] == 0) error = true;
            }
            if (error)
            {
                Console.WriteLine(-1);
                return;
            }
            int ans = 0;
            for(int i = 1; i <= N; i++)
            {
                ans = ans * 10 + b[i];
            }
            Console.WriteLine(ans);
        }
    }
}
