// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let nm = readInts()
    let (n, m) = (nm[0], nm[1])
    var aryAns = [Int](repeating: -1, count: n)
    for _ in 1...m {
        let sc = readInts()
        let (s, c) = (sc[0], sc[1])
        if aryAns[s-1] != -1 && aryAns[s-1] != c{
            print(-1)
            return
        }
        aryAns[s-1] = c
    }
    if aryAns[0] <= 0 {
        print(-1)
        return
    }
    var ans = String()
    for i in aryAns {
        ans += i == -1 ? "0": String(i)
    }
    print(ans)
    
}

main()


