using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        getAns(n, m);
    }
    static void getAns(int n, int m)
    {
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] = -1;
        for (int i = 0; i < m; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var s = int.Parse(line[0]) - 1;
            var c = int.Parse(line[1]);
            if (a[s] == -1) a[s] = c;
            else
            {
                if (a[s] != c) { Console.WriteLine(-1); return; }
            }
        }
        if (n == 1) { Console.WriteLine(a[0]); return; }
        var first = true;
        var ans = "";
        for (int i = 0; i < n; i++)
        {
            if (first && (a[i] == -1 | a[i] == 0)) { Console.WriteLine(-1); return; }
            else if (first && a[i] != -1) { ans += a[i].ToString(); first = false; }
            else if (!first && a[i] == -1) ans += "0";
            else ans += a[i].ToString();
        }
        Console.WriteLine(ans);
    }
}
