
if __name__ == '__main__':
    n, m = [int(i) for i in input().split()]

    d = {}
    result = -1
    for i in range(m):
        s, c = [int(i) for i in input().split()]

        if s in d.keys():
            if d[s] != c:
                print(result)
                exit()
            else:
                pass
        else:
            d[s] = c

    tmp = ""
    for i in range(1, n + 1):
        if i in d.keys():
            tmp += str(d[i])
        else:
            if i == 1:
                tmp += "1"
            else:
                tmp += "0"

    if tmp != str(int(tmp)):
        result = -1
    else:
        result = tmp
    
    print(result)
