using System;

namespace ABC157C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nms = Console.ReadLine().Split();
            int n = int.Parse(nms[0]);
            int m = int.Parse(nms[1]);
            string scs;
            int[] s = new int[m];
            int[] c = new int[m];
            int[] a = new int[n];
            for(int i = 0; i < n; i++)
            {
                a[i] = -1;
            }
            int ans = -1;
            for(int i = 0; i < m; i++)
            {
                scs = Console.ReadLine();
                string[] sc = scs.Split();
                s[i] = int.Parse(sc[0]);
                c[i] = int.Parse(sc[1]);
            }
            for(int i = 0; i < m; i++)
            {
                if((a[s[i] - 1] != -1 && a[s[i] - 1] != c[i]) || (s[i] == 1 && c[i] == 0))
                {
                    for(int j = 0; j < n; j++)
                    {
                        a[j] = -1;
                    }
                    break;
                }
                a[s[i] - 1] = c[i];
            }
            for(int i = 0; i < n; i++)
            {
                if (a[i] != -1)
                {
                    ans += a[i] * (int)Math.Pow(10,n-i-1);
                    if((int)Math.Pow(10,n-i-1) == 1)
                    {
                        ans += 1;
                    }
                }
            }
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}
