def main(n,m,sc):
    r = [-1]*n
    for i in range(len(sc)):
        x,y = sc[i]
        if r[x-1] != -1 and r[x-1] != y:
            return -1
        else:
            r[x-1] = y
    if r[-1] <= 0:
        return -1
    res = ""
    for i in range(len(r)):
        res = res + (str(r[i]) if r[i]!=-1 else "0")
    return res

n,m = list(map(int, input().split()))
sc = [list(map(int, input().split())) for _ in range(m)]
print(main(n,m,sc))