using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int[] nm = ReadLineIntArray();
        string rtn = "";
        for (int i = 0; i < nm[0];i++) {
            rtn = rtn + "9"; 
        }
        bool flg = true;
        bool[] flgArr = new bool[3];
        for (int i = 0; i < nm[1];i++) {
            int[] sc = ReadLineIntArray();
            flgArr[sc[0] -1] = true;
            string wk = "";
            for (int j = 0; j < nm[0];j++) {
                if (sc[0] - 1 == j) {
                    if (int.Parse(rtn.Substring(sc[0] -1, 1)) > sc[1]) {
                        wk = wk + sc[1].ToString();
                    } else {
                        wk = wk + rtn.Substring(j, 1);
                    }
                } else {
                    wk = wk + rtn.Substring(j, 1);
                }
            }
            rtn = wk;
        }
        string wk_rtn = "";
        for (int i = 0; i < nm[0];i++) {
            if (!flgArr[i]) { 
                wk_rtn = wk_rtn + "0"; 
            } else {
                wk_rtn = wk_rtn + rtn.Substring(i, 1); 
            }
        }
        if (flg) {
            int int_rtn = int.Parse(wk_rtn);
            if (int_rtn.ToString().Length == nm[0]) {
                Console.WriteLine(int_rtn);
            } else {
                Console.WriteLine(-1);
            }
        } else {
            Console.WriteLine(-1);
        }
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"};
    static int[] intArray = new int[10];
    static List<int> intList = new List<int>();
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private List<int> ReadLineIntList() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToList();}
    static private List<long> ReadLineLongList() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToList();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string IntToNString(int x, int n) {
        var nstring = "";
        var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int r = 1;
        int q = x;
        while (q > 0) {
            r = q % n;
            nstring += numbers[r];
            q = q / n;
        }
        return string.Join("",nstring.Reverse());
     }
}