def resolve():
    n, m = map(int,input().split())
    li =  [list(map(int,input().split())) for i in range(m)]
    dc = {}
    for l in li:
        if l[0] in dc and l[1] != dc[l[0]]:
            return -1
        dc[l[0]] = l[1]
    
    for i in range(1, n+1):
        if i == 1:
            if 1 in dc:
                if dc[1] == 0:
                    return -1
                else:
                    ans = str(dc[1])
            else:
                if n == 1:
                    return 0
                else:
                    ans = '1'
            continue
        if i in dc:
            ans += str(dc[i])
        else:
            ans += '0'
    return int(ans)

print(resolve())     