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

class C {
    static void Main(string[] args) {
        var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = st[0];
        int M = st[1];
        var s = new int[M];
        var c = new int[M];

        //桁ごとの数字を配列に収める
        var keta = new int[N];
        for (int i = 0; i < N; i++) {
            keta[i] = -1;
        }

        for (int i = 0; i < M; i++) {
            var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            s[i] = x[0] - 1;
            c[i] = x[1];

            if (keta[s[i]] == -1) {
                keta[s[i]] = c[i];
            } else {
                if (keta[s[i]] != c[i]) {
                    Console.WriteLine(-1);
                    return;
                }
            }
            if (s[i] == 0 && c[i] == 0) {
                Console.WriteLine(-1);
                return;
            }
        }

        string ans = "";

        for (int i = 0; i < N; i++) {
            if (keta[i] == -1) {
                ans = ans + "0";
            } else {
                ans = ans + keta[i].ToString();
            }
        }


        Console.WriteLine(ans);


    }
}