using System;
using System.Collections.Generic;
using System.Linq;
 
public class C {
    public static void Main(){
        string[] line = Console.ReadLine().Split(' ');
        int N = int.Parse(line[0]);
        int M = int.Parse(line[1]);
        Dictionary<int, int> numberinfo = new Dictionary<int, int>();
        bool cannotOutput = false;
        for (int i=0;i<M;i++)
        {
            line = Console.ReadLine().Split(' ');
            int s = int.Parse(line[0]);
            int c = int.Parse(line[1]);
            if (numberinfo.ContainsKey(s))
            {
                if (numberinfo[s] != c)
                {
                    cannotOutput = true;
                    break;
                }
            }
            else 
            {
                numberinfo[s] = c;
            }
        }
        if (cannotOutput) Console.WriteLine(-1);
        else
        {
            int[] number = new int[N];
            for (int i=0;i<N;i++) number[i] = 0;
            foreach (int s in numberinfo.Keys)
            {
                number[s-1] = numberinfo[s];
            }
            if (N==1&&number[0]==0) Console.WriteLine(0);
            else if (number[0]==0) Console.WriteLine(-1);
            else
            {
                string output = "";
                for (int i=0;i<N;i++)
                {
                    output += number[i]+"";
                }
                Console.WriteLine(output);
            }
        }
    }
}