// 🐋💭
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)
    var aryS = [Int]()
    var aryC = [Int]()
    
    for _ in 0..<m {
        let sc = readInts()
        aryS.append(sc[0])
        aryC.append(sc[1])
    }
    
    var ans = String()
    if m == 0 {
        if n == 1 {
            print(0)
            return
        }
        else {
            for i in 0..<n {
                ans += i == 0 ? "1": "0"
            }
            print(ans)
            return
        }
    }
    
    for i in 0..<m {
        if aryAns[aryS[i]-1] != -1 && aryAns[aryS[i]-1] != aryC[i]{
            print(-1)
            return
        }
        aryAns[aryS[i]-1] = aryC[i]
    }
    if aryAns[0] == 0 {
        print(-1)
        return
    }
    
    for i in 0..<m {
        ans += aryAns[i] == -1 ? "0": String(aryAns[i])
    }
    print(ans)
}

main()


