inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
l = inp.shift().split(' ')
N = l.shift() * 1
M = l.shift() * 1 
a = new Array(N)
b = true
for (i=0; i<M; i++) {
  l = inp.shift().split(' ')
  if (a[l[0] - 1] === undefined) {
      a[l[0] - 1] = l[1]
  } else if (a[l[0] - 1] != l[1]) {
      b = false
      break;
  }
}
if (M === 0) {
    b = false
} else if (b) {
    for (i=0; i<N; i++) {
        if (i === 0 && a[i] === undefined) {
            a[i] = 1
            continue;
        }
        if (a[i] === undefined) {
            a[i] = 0
        }
    }
    ans = a.join("") * 1
    if (a.join("") == ans && N == (ans + "").length) {
        ans = a.join("") * 1
        b = true
    } else {
        b = false
    }
}
console.log(b ? ans : -1)