"use strict"
function Main(stdin){
stdin = stdin.trim().split("\n").reverse();
let stdout = [];
function input(){return stdin.pop()};
function maput(){return input().split(" ").map(n=>parseInt(n))};
function print(x){stdout.push(x)};
function exist(x, xs){return new Set(xs).has(x)}
function max(x){return x.reduce(function(a,b){ return Math.max(a,b) }) }
function min(x){return x.reduce(function(a,b){ return Math.min(a,b) }) }
function sum(x){return x.reduce(function(a,b){ return a+b }) }
function sorting(x, index){x.sort((a, b) => a[index] - b[index])}
function all(x){return x.reduce(function(a,b){ return a && b }) }
function any(x){return x.reduce(function(a,b){ return a || b }) }
function list(iterable){return Array.from(iterable)}
function vint(iterable){return Array.from(iterable, x => parseInt(x))}
function tile(val, len){return Array(len).fill(val)}
const range = (start, stop, step) => Array.from(
    { length: (stop - start) / step }, (_, i) => start + (i * step));
/*START*/

let nm = maput()
let n = nm[0]
let m = nm[1]
let a = new Array(m)
for (let i = 0; i < m; i++){ a[i] = input() }


let x = 10 ** (n - 1)
if (n == 1){ x = 0 }
let ans = [-1]


while (x < 10 ** n){
    
    let s = String(x)    
    let b = new Array(m)
    for (let i = 0; i < m; i++){     
        b[i] = (s[parseInt(a[i][0]) - 1] == a[i][2])
    }
    
    if (all(b)){
        ans.push(x)
        break
    }
    x++
}

print(ans[ans.length - 1])


/*
n,m = map(int, input().split())
a = [input() for _ in range(m)]

x = 10 ** (n - 1)
if n == 1: x = 0
ans = [-1]

while x < 10 ** n:
    s = str(x)
    if all(s[int(ai[0]) - 1] == ai[2] for ai in a):
        ans.append(x)
        break
    x += 1

print(ans[-1])
*/



/*END*/
console.log(stdout.join("\n"));
return stdout
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"))