import Foundation

/*
// 1
let N = Int(readLine()!)!

// 1 2
let split = readLine()!.componentsSeparatedByString(" ")
let N = Int(split[0])!
let R = Int(split[1])!

// 1 2 3 4 5
let array = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }
*/
// 1 2

let split = readLine()!.componentsSeparatedByString(" ")
let N = Int(split[0])!
let M = Int(split[1])!
var consts = [[Int]]()
var answer = 1
for _ in 1..<N { answer = answer * 10 }
var notExist = false

for i in 0 ..< M {
  let array = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }
  consts.append(array)
}

var temp = 0
for i in 0 ..< M {
  var skip = false
  let const = consts[i]
  if const[0] == M && const[1] == 0 {
    notExist = true
    break
  }
  for j in i + 1 ..< M {
    if const[0] == consts[j][0] && const[1] != consts[j][1] {
        notExist = true
		break
    } else if const[0] == consts[j][0] && const[1] == consts[j][1] {
        skip = true
		break
    }
  }
  if !skip {
    var pow = 1
  	for _ in 1 ..< N - const[0] + 1 { pow = pow * 10 }
    pow = const[1] * pow
    temp += pow
  }
}

if notExist {
  print(-1)
} else if N == 1 && temp == 0 {
  print(0)
} else if temp < answer  {
  print(answer + temp)
} else {
  print(temp)
}