using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC
{
    partial 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];

            for (int i = 0; i < M; i++)
            {
                string[] sc = Console.ReadLine().Split(' ');
                s[i] = int.Parse(sc[0]);
                c[i] = int.Parse(sc[1]);
            }

            int ans = 0;

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    if (s[i] == s[j])
                    {
                        if (c[i] != c[j])
                        {
                            Console.WriteLine("-1");
                            return;
                        }
                    }
                }
            }

            for (int i = 0; i < M; i++)
            {
                for (int j = i + 1; j < M; j++)
                {
                    if (s[i] == s[j])
                    {
                        if (c[i] == c[j])
                        {
                            c[j] = 0;
                        }
                    }
                }
            }

            for (int i = 0; i < M; i++)
            {
                ans += (int)Math.Pow(10, N - s[i]) * c[i];
            }


            if (ans.ToString().Length != N)
            {
                Console.WriteLine("-1");
                return;
            }

            Console.WriteLine(ans);

        }
    }
}
