using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int N = int.Parse (str[0]);
            int M = int.Parse (str[1]);

            char[] ans = new char[N];
            for (int i = 0; i < ans.Length; i++)
            {
                ans[i] = '0';
            }

            for (int i = 0; i < M; i++)
            {
                str = Console.ReadLine ().Split (' ');
                int s = int.Parse (str[0]) - 1;
                char c = str[1][0];

                if (s == 0 && c == '0')
                {
                    Console.Write (-1);
                    return;
                }
                if (ans[s] != '0')
                {
                    if (ans[s] == c)
                    {
                        break;
                    }
                    else
                    {
                        Console.Write (-1);
                        return;
                    }
                }
                else
                {
                    ans[s] = c;
                }
            }

            if (ans[0] == '0') ans[0] = '1';

            Console.Write (ans);
        }
    }

    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}